Authentication
Understanding authentication at runtime
Abstract
Chapter 1. Understanding authentication at runtime Copy linkLink copied to clipboard!
Developers building images may need to configure authentication and use secrets to handle sensitive data safely within the build process. Access to build resources is governed by role-based access control (RBAC), defined by cluster administrators to ensure only authorized users can act securely.
1.1. Build secret annotation Copy linkLink copied to clipboard!
Add an annotation to a build secret to ensure the build controller reconciles on create, update, or delete events for the referenced build secret.
The following example shows the usage of an annotation with a secret:
where:
<pull_secret>- Specifies the Base64-encoded pull secret used by the build.
build.shipwright.io/referenced.secret-
Specifies the value of the
build.shipwright.io/referenced.secretannotation.
This annotation ensures the controller ignores secret events unless the secret is explicitly referenced by a build. For example, if a secret does not include this annotation, the build controller will not reconcile when that secret changes, even if an event is triggered. Reconciling on relevant events allows the build controller to re-run build configuration validations, helping detect missing or misconfigured dependencies early.
1.2. Authentication to Git repositories Copy linkLink copied to clipboard!
You can define the following types of authentication for a Git repository:
- Basic authentication
- Secure Shell (SSH) authentication
You can configure a Git secret with these authentication methods.
1.2.1. Basic authentication Copy linkLink copied to clipboard!
Configure basic authentication credentials for a Git repository by creating a Kubernetes secret with a username and password. The following example shows a Git basic-auth secret referenced by a build:
where:
type-
Specifies the Kubernetes secret type.
kubernetes.io/basic-authindicates that the secret contains credentials for basic authentication. stringData- Specifies the username and password used for basic authentication to the Git repository referenced by the build.
1.2.2. SSH authentication Copy linkLink copied to clipboard!
With Secure Shell (SSH) authentication, configure Tekton annotations to specify the hostname of the Git repository provider. For example, use github.com for GitHub or gitlab.com for GitLab.
The following example shows a Kubernetes secret configured for SSH authentication to a Git repository:
where:
type-
Specifies the Kubernetes secret type.
kubernetes.io/ssh-authindicates that the secret contains SSH credentials. ssh-privatekey-
Specifies the Base64-encoded SSH private key used to authenticate to the Git repository. You can generate this value by running
base64 ~/.ssh/id_rsa, where~/.ssh/id_rsais the default location of the SSH private key commonly used for Git authentication.
1.2.3. Usage of Git secret Copy linkLink copied to clipboard!
After creating a secret in the relevant namespace, you can reference it in your Build custom resource (CR). You can configure the Git secret to use either basic authentication or Secure Shell (SSH) authentication.
The following example shows the usage of a Git secret with SSH authentication type:
The following example shows the usage of a Git secret with basic authentication type:
1.3. Authentication to container registries Copy linkLink copied to clipboard!
To push images to a private container registry, you must create a secret in the relevant namespace and then reference it in your Build custom resource (CR).
Prerequisites
- You have installed the Builds for Red Hat OpenShift Operator on the OpenShift Container Platform cluster.
-
You have installed the
ocCLI.
Procedure
Run the following command to generate a
secretobject:oc --namespace <namespace> create secret docker-registry <container_registry_secret_name> \ --docker-server=<registry_host> \ --docker-username=<username> \ --docker-password=<password> \ --docker-email=<email_address>
$ oc --namespace <namespace> create secret docker-registry <container_registry_secret_name> \ --docker-server=<registry_host> \ --docker-username=<username> \ --docker-password=<password> \ --docker-email=<email_address>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
<namespace>- Specifies the namespace where you want to create the secret.
<container_registry_secret_name>-
Specifies the name of the
Secretresource that stores the container registry credentials. <registry_host>-
Specifies the registry URL in the format
https://<registry_server>/<registry_host>. <username>- Specifies the registry username.
<password>- Specifies the password or an access token for the container registry.
<email_address>- Specifies the email address associated with the container registry credentials.
Run the following command to annotate the secret:
oc --namespace <namespace> annotate secrets <container_registry_secret_name> build.shipwright.io/referenced.secret='true'
$ oc --namespace <namespace> annotate secrets <container_registry_secret_name> build.shipwright.io/referenced.secret='true'Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
<namespace>- Specifies the namespace in which you want to create the secret.
<container_registry_secret_name>-
Specifies the name of the
Secretresource that stores the container registry credentials.
Set the value of the
spec.output.pushSecretfield to the secret name in yourBuildCR:Copy to Clipboard Copied! Toggle word wrap Toggle overflow where
<path_to_image>- Specifies the location of the output image.
<container_registry_secret_name>-
Specifies the name of the
Secretresource that stores the container registry credentials.
-
Run a build using the
BuildCR. The container registry credentials are verified during the image push. If authentication fails, the build does not push the image.
1.4. Role-based access control Copy linkLink copied to clipboard!
By default, builds for Red Hat OpenShift installation includes the following two cluster-wide roles for using Builds objects:
-
shpwright-build-aggregate-view: Grants read access to the Builds resources, such asBuildStrategy,ClusterBuildStrategy,Build, andBuildRun. This role is aggregated into the Kubernetesviewrole. -
shipwright-build-aggregate-edit: Grants write access to the Builds resources that are configured at namespace level. The build resources includeBuildStrategy,Build, andBuildRun. Read access is granted to allClusterBuildStrategyresources. This role is aggregated into the Kuberneteseditandadminroles.
Only cluster administrators have write access to the ClusterBuildStrategy resources by default. You can change this setting by creating a separate Kubernetes ClusterRole with the desired permissions and binding it to the appropriate users.
Legal Notice
Copy linkLink copied to clipboard!
Copyright © Red Hat
OpenShift documentation is licensed under the Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0).
Modified versions must remove all Red Hat trademarks.
Portions adapted from https://github.com/kubernetes-incubator/service-catalog/ with modifications by Red Hat.
Red Hat, Red Hat Enterprise Linux, the Red Hat logo, the Shadowman logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of the OpenJS Foundation.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation’s permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.