Skip to content

Conversation

@shoenig
Copy link
Contributor

@shoenig shoenig commented Mar 25, 2021

This PR adds the common changes for adding support for Consul Namespaces,
which is going to be a Nomad Enterprise feature. There is no new functionality
provided by this changeset and hopefully no new bugs.

@shoenig shoenig marked this pull request as draft March 25, 2021 19:16
@vercel vercel bot temporarily deployed to Preview – nomad March 29, 2021 14:28 Inactive
Copy link
Contributor Author

@shoenig shoenig Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should change before 1.0 GA; instead we can fingerprint Consul oss/ent and set a boolean to do the Right Thing without leaning on Consul error response. I'll open a followup PR for that.

go.mod Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, until Consul produces a new API version with this change.

nomad/consul.go Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This left me with a belief that we need to overhaul how Nomad handles Consul tokens. In the past the Nomad agent token was used no matter who the job submitter or what the job contained. With Connect we introduced a Consul ACL token permissions check that the job submitter had equivalent Service Identity permissions, because such a token is generated and given to the task. With Namespaces, we need to check that the job submitter has necessary service:write and kv:read permissions within their namespace - and without extensive plumbing the only safe way to do that is to parse and check the HCL ourselves. Ideally we should be actually using the job submitter's Consul ACL token and letting Consul do the ACL checks - but to do that safely requires managing AccessorID's in the Nomad Client, wiring up some RPC's with Nomad Server to get the SecretID from Consul and passing it back to the Client, who can then submit the token to Consul without it ever being written to the Client's disk (the security hole @schmichael points out). That seems like a lot of work so it'll have to wait for another day.

Copy link
Contributor Author

@shoenig shoenig Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation in ent is slightly different

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work here @shoenig... this is a brutal amount of plumbing code to write! I've left some minor comments and suggestions, but mostly LGTM.

}

info := bindataFileInfo{name: "command/assets/connect-short.nomad", size: 997, mode: os.FileMode(436), modTime: time.Unix(1612560436, 0)}
info := bindataFileInfo{name: "command/assets/connect-short.nomad", size: 997, mode: os.FileMode(436), modTime: time.Unix(1616684356, 0)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file have been committed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, reverted. Still not totally familiar with the generation workflow 😞

hashMeta(h, s.CanaryMeta)
hashConnect(h, s.Connect)
hashString(h, s.OnUpdate)
hashString(h, s.Namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just spent like 15 trying to figure out why we have a hashStringIfNonEmpty function because I was worried about upgrades. But this is SHA1, so "" doesn't impact the hash. 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, TIL! We can probably remove hashStringIfNonEmpty then, maybe just doing a spot check first with some examples to make sure everything is the same before and after. For a rainy day, perhaps.

}

func TestConsulACLsAPI_CheckSIPolicy(t *testing.T) {
// CheckPermissions(ctx context.Context, namespace string, usage *structs.ConsulUsage) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// CheckPermissions(ctx context.Context, namespace string, usage *structs.ConsulUsage) error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

t.Parallel()

try := func(t *testing.T, service, token string, expErr string) {
equalError := func(t *testing.T, exp, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky, but this isn't reused anywhere so it was probably more clear to inline it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return false
}

// ConsulUsages returns a map from Consul namespace to things that will use Consul,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on centralizing this

shoenig and others added 2 commits April 5, 2021 10:03
This PR adds the common OSS changes for adding support for Consul Namespaces,
which is going to be a Nomad Enterprise feature. There is no new functionality
provided by this changeset and hopefully no new bugs.
Co-authored-by: Tim Gross <tgross@hashicorp.com>
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants