OC-POLICY-ADD-ROLE-TO-USER(1)
π oc policy add-role-to-user β the glow-up your project access deserves β¨
Okay bestie, so you know the oc CLI? This is one of its cutest little commands, straight out of the OpenShift CLI User Manuals. Let me put you on. π«Ά
π SYNOPSIS
oc policy add-role-to-user [OPTIONS]
π DESCRIPTION
So here's the tea: this command adds a role to users or service accounts for the project. That's it. That's the vibe. π
Basically, it's how you grant a user access to specific resources and actions within the current project β you do it by assigning them to a role. It creates or modifies a role binding that references the role you specified, adding the user(s) or service account(s) to the list of subjects. And here's the iconic part: the command does not require that the matching role or user/service account resources actually exist. It will create the binding successfully even when the role or user/service account doesn't exist, or when the user doesn't even have access to view them. No vibe check required, it just slays. π₯
Now, if you pass the --rolebinding-name argument, it will look for an existing role binding with that name. And listen β the role on the matching role binding MUST match the role name you supplied to the command. No cap. If you don't give a role binding name, a default name gets used. When --role-namespace is specified as a non-empty value, it MUST match the current namespace. When role-namespace is specified, the role binding will reference a namespaced role. Otherwise? The role binding will reference a cluster role resource. iykyk. β¨
Wanna learn more? Go read up on RBAC and policy, or just use the get and describe commands on these resources: clusterroles, clusterrolebindings, roles, rolebindings, users, groups, and serviceaccounts. Very much giving "do your research, bestie." π
β¨ OPTIONS β¨
--allow-missing-template-keys=trueβ If true, ignore any errors in templates when a field or map key is missing in the template. Only applies togolangandjsonpathoutput formats. No stress if a key's missing. πββοΈ--dry-run="none"β Must be"none","server", or"client". If it's the client strategy, only print the object that would be sent, without actually sending it. If it's the server strategy, submit a server-side request without persisting the resource. It's giving "look but don't touch." π-o,--output=""β Output format, bestie. One of: (json,yaml,kyaml,name,go-template,go-template-file,template,templatefile,jsonpath,jsonpath-as-json,jsonpath-file). Pick your aesthetic. π¨--role-namespace=""β namespace where the role is located: empty means a role defined in cluster policy. It's the "where's the role at" flag. π--rolebinding-name=""β Name of the rolebinding to modify or create. If left empty, it creates a new rolebinding with a default name. Name it or let the universe decide. π¦-z,--serviceaccount=[]β service account in the current namespace to use as a user. Shoutout to the service accounts, they're doing amazing sweetie. π€--show-managed-fields=falseβ If true, keep themanagedFieldswhen printing objects in JSON or YAML format. For the detail girlies. π--template=""β Template string or path to template file to use when-o=go-templateor-o=go-template-file. The template format is golang templates [ β¨http://golang.org/pkg/text/template/#pkg-overviewβ© ]. Go off, template queen. π
πΈ OPTIONS INHERITED FROM PARENT COMMANDS πΈ
These are the flags you get from the big oc energy. Inherited like your mom's good taste. π
--as=""β Username to impersonate for the operation. User could be a regular user or a service account in a namespace. Be someone else for a sec, it's fine. π--as-group=[]β Group to impersonate for the operation. This flag can be repeated to specify multiple groups. Stack 'em up. π--as-uid=""β UID to impersonate for the operation.--as-user-extra=[]β User extras to impersonate for the operation. This flag can be repeated to specify multiple values for the same key. Extra as in extra. π--cache-dir="/homeless-shelter/.kube/cache"β Default cache directory. Yes, that's the actual path, no I'm not joking. π--certificate-authority=""β Path to a cert file for the certificate authority.--client-certificate=""β Path to a client certificate file for TLS.--client-key=""β Path to a client key file for TLS.--cluster=""β The name of the kubeconfig cluster to use.--context=""β The name of the kubeconfig context to use.--disable-compression=falseβ If true, opt-out of response compression for all requests to the server. Sometimes you just want it raw. π«£--insecure-skip-tls-verify=falseβ If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. β οΈ Bestie. Be careful with that one, fr fr.--kubeconfig=""β Path to the kubeconfig file to use for CLI requests.--kuberc=""β Path to the kuberc file to use for preferences. This can be disabled by exportingKUBECTL_KUBERC=falsefeature gate or turning off the featureKUBERC=off.--match-server-version=falseβ Require server version to match client version. Matching outfits, but for versions. π―ββοΈ-n,--namespace=""β If present, the namespace scope for this CLI request.--profile="none"β Name of profile to capture. One of(none|cpu|heap|goroutine|threadcreate|block|mutex).--profile-output="profile.pprof"β Name of the file to write the profile to.--request-timeout="0"β The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g.1s,2m,3h). A value of zero means don't timeout requests. Zero = infinite patience, iconic. π§ββοΈ-s,--server=""β The address and port of the Kubernetes API server.--tls-server-name=""β Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used.--token=""β Bearer token for authentication to the API server.--user=""β The name of the kubeconfig user to use.--warnings-as-errors=falseβ Treat warnings received from the server as errors and exit with a non-zero exit code. Harsh, but okay. π€
π¦ EXAMPLE π¦
Like, actual examples. This is how you use it, bestie:
# Add the 'view' role to user1 for the current project
oc policy add-role-to-user view user1
# Add the 'edit' role to serviceaccount1 for the current project
oc policy add-role-to-user edit -z serviceaccount1
See? Easy. Iconic. Slayed. π β¨
π SEE ALSO π
oc-policy(1) β go read the rest of the family, they're all cute.
π HISTORY π
June 2016, Ported from the Kubernetes man-doc generator. A little slay from way back, but still relevant. β³
Sign-off realness: this manual comes to you from Openshift β the Openshift CLI User Manuals β and it was last touched up in June 2016. She's vintage but she works. ππ
That's the whole page, bestie. Now go grant somebody a role and make it everyone's problem. π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: openshift 4.22.0-202605222050
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms