consul icon indicating copy to clipboard operation
consul copied to clipboard

HTTP 500 when deregistering nonexistent check with ACLs enabled

Open sgrimm-sg opened this issue 7 years ago • 7 comments

Overview of the Issue

With ACLs disabled, deregistering a nonexistent check with the local agent responds with HTTP 200 and no response body. With ACLs enabled, even with a default policy of allow, the agent responds with HTTP 500 Internal Server Error and a text/plain response body with a human-readable "Unknown check" error message.

For an operation that isn't forbidden by the ACL, I expected the agent to respond the same way with and without ACLs enabled, and I didn't expect to get an HTTP 500 response from a healthy agent.

This came up because my application tries to deregister its checks at startup to deal with cases where a stale check is left behind when a previous run crashes or is killed. My workaround for now is to simply ignore the HTTP 500 on the deregister request and proceed with registering the service and check (which works as expected with ACLs enabled).

Reproduction Steps

The problem reproduces with a local agent in dev mode (though I originally ran into it in a non-dev environment).

  1. Run the agent without ACLs enabled: consul agent -dev
  2. Deregister a nonexistent check: curl -v --request PUT http://127.0.0.1:8500/v1/agent/check/deregister/nonexistent-check-id
  3. Confirm that it returns HTTP 200.
  4. Restart the agent with ACLs enabled: consul agent -dev -hcl '{ "acl": { "default_policy": "allow", "enabled": true } }'
  5. Deregister a nonexistent check: curl -v --request PUT http://127.0.0.1:8500/v1/agent/check/deregister/nonexistent-check-id
  6. It returns HTTP 500.

Consul info for both Client and Server

Client info
agent:
	check_monitors = 0
	check_ttls = 0
	checks = 0
	services = 0
build:
	prerelease = 
	revision = ea5210a+
	version = 1.4.4
consul:
	acl = enabled
	bootstrap = false
	known_datacenters = 1
	leader = true
	leader_addr = 127.0.0.1:8300
	server = true
raft:
	applied_index = 12
	commit_index = 12
	fsm_pending = 0
	last_contact = 0
	last_log_index = 12
	last_log_term = 2
	last_snapshot_index = 0
	last_snapshot_term = 0
	latest_configuration = [{Suffrage:Voter ID:25942a0b-2570-b677-a54a-7f5c04f66318 Address:127.0.0.1:8300}]
	latest_configuration_index = 1
	num_peers = 0
	protocol_version = 3
	protocol_version_max = 3
	protocol_version_min = 0
	snapshot_version_max = 1
	snapshot_version_min = 0
	state = Leader
	term = 2
runtime:
	arch = amd64
	cpu_count = 8
	goroutines = 81
	max_procs = 8
	os = darwin
	version = go1.12.1
serf_lan:
	coordinate_resets = 0
	encrypted = false
	event_queue = 1
	event_time = 2
	failed = 0
	health_score = 0
	intent_queue = 0
	left = 0
	member_time = 1
	members = 1
	query_queue = 0
	query_time = 1
serf_wan:
	coordinate_resets = 0
	encrypted = false
	event_queue = 0
	event_time = 1
	failed = 0
	health_score = 0
	intent_queue = 0
	left = 0
	member_time = 1
	members = 1
	query_queue = 0
	query_time = 1
Server info
agent:
	check_monitors = 0
	check_ttls = 0
	checks = 0
	services = 0
build:
	prerelease = 
	revision = ea5210a+
	version = 1.4.4
consul:
	acl = enabled
	bootstrap = false
	known_datacenters = 1
	leader = true
	leader_addr = 127.0.0.1:8300
	server = true
raft:
	applied_index = 12
	commit_index = 12
	fsm_pending = 0
	last_contact = 0
	last_log_index = 12
	last_log_term = 2
	last_snapshot_index = 0
	last_snapshot_term = 0
	latest_configuration = [{Suffrage:Voter ID:25942a0b-2570-b677-a54a-7f5c04f66318 Address:127.0.0.1:8300}]
	latest_configuration_index = 1
	num_peers = 0
	protocol_version = 3
	protocol_version_max = 3
	protocol_version_min = 0
	snapshot_version_max = 1
	snapshot_version_min = 0
	state = Leader
	term = 2
runtime:
	arch = amd64
	cpu_count = 8
	goroutines = 81
	max_procs = 8
	os = darwin
	version = go1.12.1
serf_lan:
	coordinate_resets = 0
	encrypted = false
	event_queue = 1
	event_time = 2
	failed = 0
	health_score = 0
	intent_queue = 0
	left = 0
	member_time = 1
	members = 1
	query_queue = 0
	query_time = 1
serf_wan:
	coordinate_resets = 0
	encrypted = false
	event_queue = 0
	event_time = 1
	failed = 0
	health_score = 0
	intent_queue = 0
	left = 0
	member_time = 1
	members = 1
	query_queue = 0
	query_time = 1

Operating system and Environment details

Original environment where I encountered the problem: Ubuntu 18.04 on x86_64 (EC2 instances at AWS)

Reproduces locally on my laptop: OS X 10.14.3, Intel Core i7

Log Fragments

    2019/05/09 10:26:34 [ERR] http: Request PUT /v1/agent/check/deregister/nonexistent-check-id, error: Unknown check "nonexistent-check-id" from=127.0.0.1:62317
    2019/05/09 10:26:34 [DEBUG] http: Request PUT /v1/agent/check/deregister/nonexistent-check-id (129.969µs) from=127.0.0.1:62317

sgrimm-sg avatar May 09 '19 17:05 sgrimm-sg

This behavior is coming from here:

https://github.com/hashicorp/consul/blob/d4ebbe064d166027f6e30f4682173b71eedcd79b/agent/acl.go#L202-L204

It will require some investigation to determine why it was done this way.

mkeeler avatar May 09 '19 17:05 mkeeler

From a security perspective you probably don't want to disclose whether or not an asset exists to a caller that does not have permission to it. Given that, if the access check cannot be performed because the asset does not exist, one would expect a 403 to be returned so the caller is informed that they don't have access. 500 is just wrong and not helpful at all.

If the token presented has the global management policy then the call should always succeed and return 404, since one doesn't need the asset to exist in order to determine access.

tkoestler avatar May 10 '19 16:05 tkoestler

I'm unfamiliar with Consul's internals, so maybe it's the only viable option, but returning 403 here seems wrong to me from a semantic point of view. You'd end up with the following sequence:

  1. Deregister a check that doesn't exist, get HTTP 403
  2. Register the exact same check, get HTTP 200
  3. Deregister the check now that it exists, get HTTP 200

At which point you can no longer trust that HTTP 403 really indicates a permission problem.

sgrimm-sg avatar May 10 '19 17:05 sgrimm-sg

I'm not familiar with Consul's internals either, I'm speaking generally, though I did take a peak at the code linked above...

I also don't like that 403 becomes a little ambiguous in a case like this, as it could mean not-found. But if you return 404 you may be allowing someone without access to know something they should not. That information might be of interest to an attacker.

The limitation here is the reliance on the asset existing to determine if the caller has permission to check its existence. That is a bit of a paradox and the best you can do in that case, without raising a security concern, is return 403. Ideally, permission to query for the existence of an asset would be related to the asset's container and not the asset itself, like it typically would on a file system. Then there is no paradox and everything could be made to behave as one would expect it to.

tkoestler avatar May 10 '19 18:05 tkoestler

Hey there, We wanted to check in on this request since it has been inactive for at least 60 days. If you think this is still an important issue in the latest version of Consul or its documentation please reply with a comment here which will cause it to stay open for investigation. If there is still no activity on this issue for 30 more days, we will go ahead and close it.

Feel free to check out the community forum as well! Thank you!

stale[bot] avatar Oct 21 '19 19:10 stale[bot]

Hey there, This issue has been automatically closed because there hasn't been any activity for at least 90 days. If you are still experiencing problems, or still have questions, feel free to open a new one :+1:

stale[bot] avatar Nov 20 '19 19:11 stale[bot]

Hey there,

This issue has been automatically locked because it is closed and there hasn't been any activity for at least 30 days.

If you are still experiencing problems, or still have questions, feel free to open a new one :+1:.

ghost avatar Jan 25 '20 02:01 ghost