Using OCI Connector to Deploy Workloads in a Secretless Way
In a Kubernetes cluster, pulling images from private registries typically requires distributing registry credentials to namespaces, which increases the risk of credential leakage.
The OCI Connector provides a secretless solution by acting as a proxy for the registry. This allows users to access private registries without storing long-term passwords or robot tokens in every namespace, thereby maximizing credential security.
This guide demonstrates how to use the OCI Connector to deploy workloads that need to pull images from private OCI registries. The OCI Connector functions as a reverse proxy between your Kubernetes cluster and the OCI registry, handling authentication and image retrieval.
TOC
Feature OverviewPrerequisitesOverviewOperational StepsStep 1: Create ConnectorStep 2: Create a ServiceAccount TokenStep 3: Create an Image Pull SecretStep 4: Patch ServiceAccount with Image Pull SecretStep 5: Deploy the WorkloadStep 6: Verify Pod StatusTroubleshootingCommon IssuesVerification CommandsConclusionFeature Overview
When deploying workloads with the OCI Connector, keep the following key points in mind:
- To enable image pulls via the OCI Connector proxy in the Kubernetes runtime, you must configure the ConnectorOCI to expose its service using either NodePort or Ingress. Refer to the Installation Guide for detailed setup instructions.
- The image address specified in your workload will be automatically rewritten to point to the OCI Connector proxy. Since the proxy uses HTTP, you must configure the runtime to allow insecure registries.
- The OCI Connector acts as a reverse proxy for the OCI registry, handling authentication and image pulls on behalf of your workloads.
- The OCI Connector proxy authenticates clients using their service account tokens, ensuring that only authorized workloads can access the specified connector.
Prerequisites
- ConnectorsCore is installed and running in the cluster: Ensure that ConnectorsCore is deployed in your cluster.
- ConnectorOCI is installed and exposed externally (NodePort or Ingress): Deploy ConnectorOCI and expose it outside the cluster. See the Installation Guide for details.
- Access to a private OCI registry: You must have valid credentials and access to the target registry.
- kubectl configured: Ensure
kubectlis installed and configured to access your cluster.
With the OCI Connector, you can securely pull images from private registries in your Kubernetes cluster without storing credentials on the client side. This approach ensures that sensitive credentials are managed centrally and never exposed to individual workloads or users.
The OCI Connector enables seamless, credential-free image pulls for pods by proxying authentication and image requests through a secure, centralized service.
Overview
The process involves several key steps:
- Creating a Connector resource that defines the connection to your OCI registry.
- Setting up authentication secrets.
- Creating a ServiceAccount token for internal authentication.
- Configuring image pull secrets.
- Deploying the workload with the appropriate annotations.
Operational Steps
Step 1: Create Connector
First, create a namespace for the demo:
Next, create a Connector resource that defines the connection to your OCI registry. This resource will manage authentication and proxy operations.
Recommendation: Use a
robot accountfor registry access instead of anadminaccount if your OCI registry supports it.
Explanation:
- The
Connectorresource defines the connection parameters including the registry address and authentication method - The
Secretresource stores the registry credentials securely - The
connectorClassName: ocispecifies that this is an OCI-type connector - The
tokenAuthauthentication method is used for token-based authentication
Now, we have created a connector in the namespace oci-connector-demo, and the connector status is Ready.
Step 2: Create a ServiceAccount Token
Generate a token for the default ServiceAccount in your namespace:
This token will be used for pulling images through the connector proxy. Any ServiceAccount with permission to access the connector can be used as a pull secret for the pod. For more information on Connector resource permissions, see Connector Scope Permissions.
Explanation:
- This token will be used to authenticate requests to the connector proxy
- The token is scoped to the specific namespace (
oci-connector-demo) - Store this token securely as it will be used in the next step
Note: ServiceAccount tokens have an expiration time (default: 1 hour). You can use the
--durationflag to extend the expiration. For more details, see the Kubernetes documentation.
Step 3: Create an Image Pull Secret
Create a registry secret using the ServiceAccount token:
Explanation:
The docker-server points to the connector proxy service address in the cluster, you can get the address from the connector status
- The
docker-usernameis set to "u" (a placeholder username) - The
docker-passworduses the Service Account token from the previous step - The
docker-emailcan be any valid email address (used for CNCF Distribution Registry compatibility)
Step 4: Patch ServiceAccount with Image Pull Secret
Attach the image pull secret to the ServiceAccount so that pods using this ServiceAccount can automatically use the secret for image pulling.
Explanation:
- This command adds the
oci-connector-secretto theimagePullSecretslist of the default ServiceAccount - Any pod using this ServiceAccount will automatically use this secret for image pulling
- This eliminates the need to specify the secret in each pod definition
This ensures that any pod using this ServiceAccount will automatically use the secret for image pulls.
Step 5: Deploy the Workload
Create a workload (Pod in this example) with the necessary annotations to use the OCI connector.
- The
connectors.cpaas.io/connectorannotation specifies which connector to use (namespace/connector-name). - The
connectors.cpaas.io/proxy-inject: "true"label enables proxy injection for this pod. - The
imagefield should specify your original image address. - The
serviceAccountName: defaultensures the pod uses the ServiceAccount with the image pull secret.
Step 6: Verify Pod Status
After the pod is created, you can see the image address in the pod is rewritten to the connector proxy address.
Then, check that the pod is running and has successfully pulled the image through the connector proxy:
Expected Output:
Troubleshooting
Common Issues
-
Pod stuck in ImagePullBackOff:
- Ensure the connector is properly configured and running.
- Verify the ServiceAccount token is valid and not expired.
- Confirm the image pull secret is correctly attached to the ServiceAccount.
-
Authentication failures:
- Check the registry credentials in the
harbor-secret. - Ensure the connector address is accessible.
- Verify the repository parameter matches your actual repository.
- Check the registry credentials in the
-
Proxy injection not working:
- Confirm the
connectors.cpaas.io/proxy-inject: "true"label is present. - Check that the connector annotation is correctly formatted.
- Ensure the connector exists in the specified namespace.
- Confirm the
Verification Commands
Conclusion
You have now completed the process of using the OCI Connector to deploy workloads in a secretless way. This approach enhances security by centralizing credential management and eliminating the need to distribute sensitive information to individual workloads.