-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
return error when long-form sa name is used #17061
return error when long-form sa name is used #17061
Conversation
/test extended_networking_minimal |
/retest |
@@ -320,6 +321,13 @@ func (o *RoleModificationOptions) CompleteUserWithSA(f *clientcmd.Factory, cmd * | |||
return errors.New("you must specify at least one user or service account") | |||
} | |||
|
|||
// return an error if a fully-qualified service-account name is used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should instead check that all names are valid SA names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, kept this check and added an additional check for the overall validity of each given SA name
f94a3a5
to
764476d
Compare
764476d
to
34f7b71
Compare
pkg/oc/admin/policy/modify_roles.go
Outdated
// return an error if a fully-qualified service-account name is used | ||
for _, sa := range saNames { | ||
if strings.HasPrefix(sa, "system:serviceaccount") { | ||
return errors.New("--serviceaccount (-z) should only be used with short-form serviceaccount names (e.g. \"default\")") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use back ticks to avoid having to escape.
pkg/oc/admin/policy/modify_roles.go
Outdated
return errors.New("--serviceaccount (-z) should only be used with short-form serviceaccount names (e.g. \"default\")") | ||
} | ||
|
||
if len(validation.ValidateServiceAccountName(sa, false)) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why suppress the actual errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saw this done in at least one other place, so copied it; will store and append the errors to the final message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated message to show indented causes in new lines:
$ oc policy add-role-to-user admin -z :default
error: ":default" is not a valid serviceaccount name:
a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
See 'oc policy add-role-to-user -h' for help and examples.
34f7b71
to
24088e7
Compare
@enj thanks for the feedback, review comments addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment. BTW if you put:
Bug 1425398
in the commit message, the bot will link the PR with the BZ.
pkg/oc/admin/policy/modify_roles.go
Outdated
if errCauses := validation.ValidateServiceAccountName(sa, false); len(errCauses) > 0 { | ||
message := fmt.Sprintf("%q is not a valid serviceaccount name:\n", sa) | ||
for _, cause := range errCauses { | ||
message += " " + cause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use strings.Join
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, although I've seen it done both ways throughout the code - would one format over the other make much difference here?
bug: 1425398 Returns an error when the long-form name of a ServiceAccount is used with the --serviceaccount (-z) flag in `oc policy ...' commands, or if the name given is invalid.
24088e7
to
d70ebd6
Compare
/test extended_conformance_install_update |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: enj, fabianofranz, juanvallejo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue. |
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1425398
Returns an error when the long-form name of a ServiceAccount is used
with the --serviceaccount (-z) flag in `oc policy ...' commands.
/assign enj
cc @openshift/cli-review