Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cni: allow users to set CNI args in job spec #23538

Merged
merged 6 commits into from
Jul 12, 2024
Merged

cni: allow users to set CNI args in job spec #23538

merged 6 commits into from
Jul 12, 2024

Conversation

martisah
Copy link
Contributor

This PR allows for users to set up CNI args in a job specification through the network block by adding a cni block and specifying an args field.

Resolves #16197

api/resources.go Outdated Show resolved Hide resolved
client/allocrunner/networking_cni_test.go Show resolved Hide resolved
client/taskenv/network_test.go Outdated Show resolved Hide resolved
nomad/structs/cni_config.go Outdated Show resolved Hide resolved
nomad/structs/diff.go Outdated Show resolved Hide resolved
nomad/structs/diff_test.go Show resolved Hide resolved
nomad/structs/structs.go Outdated Show resolved Hide resolved
Copy link
Member

@gulducat gulducat left a comment

Choose a reason for hiding this comment

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

we are getting very close! I have just a couple more comments, and we also should add a changelog, then let's un-draft the PR and get another set of eyes on it!

nomad/structs/diff.go Outdated Show resolved Hide resolved
nomad/structs/diff_test.go Outdated Show resolved Hide resolved
nomad/structs/cni_config.go Outdated Show resolved Hide resolved
@martisah martisah marked this pull request as ready for review July 12, 2024 15:18
@martisah martisah added backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.8.x backport to 1.8.x release line labels Jul 12, 2024
Copy link
Member

@gulducat gulducat left a comment

Choose a reason for hiding this comment

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

Huzzah!

@martisah martisah merged commit 661011f into main Jul 12, 2024
27 checks passed
@martisah martisah deleted the cni-Args branch July 12, 2024 15:47
Comment on lines +18 to +21
newMap := make(map[string]string)
for k, v := range d.Args {
newMap[k] = v
}
Copy link
Member

Choose a reason for hiding this comment

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

There's a maps.Clone helper for this.

Comment on lines +7205 to +7208
if strings.Contains(v, ";") {
err := fmt.Errorf("invalid ';' character in CNI arg value %q", v)
mErr.Errors = append(mErr.Errors, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

This illegal character check feels ad hoc; are we certain that this is an actual attack vector for CNI plugins? Also we're interpolating the values on the client (although not the keys). If I were an evil job author, I could have a value that includes a client attribute with a ; and bypass the check.

Copy link
Member

Choose a reason for hiding this comment

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

my concern was more about ergonomics than security -- I wanted to protect job authors from doing something confusingly silly. the semicolon here isn't dangerous like it might be when parsing something like a shell command or sql query, but if a user put a ; in a key or value, then it could confuse plugins that read the args, since CNI_ARGS in the end is a ;-separated string of key=vals.

e.g. given the key "bad-test-key;is-bad" the (common) library that the bridge plugin uses hits this error and the Nomad client logs

[ERROR] client.alloc_runner: prerun failed: alloc_id=29822c8b-7192-150b-cc00-9a4e827384b0 error="pre-run hook "network" failed: failed to configure networking for alloc: failed to configure network: plugin type="bridge" failed (add): ARGS: invalid pair "bad-test-key""

a similar bad;value produces similar results.

any other code (plugin, library) that parses CNI_ARGS would have to do its own error handling like that, and could potentially produce dangerous results (we can't control the entire CNI ecosystem), but the goal here is just to error way earlier, before the job is accepted, to save the user some headache and troubleshooting.

the idea of a client attribute with a ; is interesting, but if you (the user) are considering client stuff like that, I suppose I'm more comfortable with you needing to hunt down client logs to track down the error?

all that said, to your point in slack, we'll put something like this comment in the code, too, to clarify the intent and danger level (low).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/1.8.x backport to 1.8.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support CNI_ARGS parameters
3 participants