我们已经在我们的环境中为领事集群启用了ACL和TLS。我们也禁用了UI。但是当我使用URL: http://:8500/v1/coordinate/datacenters.时如何才能像这样禁用URL呢?
我通过在consulConfig.json中添加以下内容进行了测试:
"ports":{
"http": -1
}这并没有解决问题。
除了提供使用"http_config": { "block_endpoints":的建议外,如果可以解决问题,我将尝试使用ACL。
启用了ACL的第一个consul acl token create -description "Block Policy Token" -policy-name "urlblock" -token <tokenvalue>
consul acl policy create -name "urlblock" -description "Url Block Policy" -rules @service_block.hcl -token <tokenvalue> contents of service_block.hcl:"tokens": { "agent": "<agenttokenvalue>"}
agent token命令:consul acl token create -description "Block Policy Token" -policy-name "urlblock" -token <tokenvalue>
agent token并粘贴到acl -> tokens部分的consul_config.json文件中,因为"tokens": { "agent": "<agenttokenvalue>"}
不过,我仍然能够访问端点/v1/status/leader。对于这种方法有什么问题吗?
发布于 2021-06-02 20:38:43
该配置应该正确禁用HTTP服务器。我能够使用以下配置验证此工作,并使用Consuer1.9.5。
禁用领事的HTTP服务器
在代理的配置目录中创建config.json,它完全禁用HTTP端口。
config.json
{
"ports": {
"http": -1
}
}启动领事代理
$ consul agent -dev -config-file=config.json
==> Starting Consul agent...
Version: '1.9.5'
Node ID: 'ed7f0050-8191-999c-a53f-9ac48fd03f7e'
Node name: 'b1000.local'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: -1, HTTPS: -1, gRPC: 8502, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
==> Log data will now stream in as it occurs:
...注意,客户端Addr行上的HTTP端口设置为"-1“。港口现在无法通行。
测试到HTTP的连接性
$ curl localhost:8500
curl: (7) Failed to connect to localhost port 8500: Connection refused阻止对特定API端点的访问
或者,您可以使用http_config.block_endpoints配置选项阻止对特定API端点的访问,而不完全禁用HTTP。
例如:
创建名为块-endpoints.json的配置。
{
"http_config": {
"block_endpoints": [
"/v1/catalog/datacenters",
"/v1/coordinate/datacenters",
"/v1/status/leader",
"/v1/status/peers"
]
}
}使用此配置启动领事
consul agent -dev -config-file=block-endpoints.json
==> Starting Consul agent...
Version: '1.9.5'
Node ID: '8ff15668-8624-47b5-6e83-7a8bfd715a56'
Node name: 'b1000.local'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: 8502, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
==> Log data will now stream in as it occurs:
...在本例中,启用了HTTP并侦听端口8500。
测试到HTTP的连接性
如果向某个阻塞端点发出请求,则将返回以下错误。
$ curl localhost:8500/v1/status/peers
Endpoint is blocked by agent configuration但是,仍然允许访问其他端点。
$ curl localhost:8500/v1/agent/members
[
{
"Name": "b1000.local",
"Addr": "127.0.0.1",
"Port": 8301,
"Tags": {
"acls": "0",
"build": "1.9.5:3c1c2267",
"dc": "dc1",
"ft_fs": "1",
"ft_si": "1",
"id": "6d157a1b-c893-3903-9037-2e2bd0e6f973",
"port": "8300",
"raft_vsn": "3",
"role": "consul",
"segment": "",
"vsn": "2",
"vsn_max": "3",
"vsn_min": "2",
"wan_join_port": "8302"
},
"Status": 1,
"ProtocolMin": 1,
"ProtocolMax": 5,
"ProtocolCur": 2,
"DelegateMin": 2,
"DelegateMax": 5,
"DelegateCur": 4
}
]https://stackoverflow.com/questions/67805702
复制相似问题