Skip to content

Commit 9f2614b

Browse files
xiujuan95qu1queee
authored andcommitted
Enhance auth document with a build secret annotation
Signed-off-by: Zoe <[email protected]>
1 parent 4b5759d commit 9f2614b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

docs/development/authentication.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SPDX-License-Identifier: Apache-2.0
99
The following document provides an introduction around the different authentication methods that can take place during an image build when using the Build operator.
1010

1111
- [Overview](#overview)
12+
- [Build Secrets Annotation](#build-secrets-annotation)
1213
- [Authentication for Git](#authentication-for-git)
1314
- [Basic authentication](#basic-authentication)
1415
- [SSH authentication](#ssh-authentication)
@@ -20,7 +21,32 @@ The following document provides an introduction around the different authenticat
2021

2122
## Overview
2223

23-
There are two places where users might need to define authentication when building images. Authentication to a container registry is the most common one, but also users might have the need to define authentications for pulling source-code from Git.
24+
There are two places where users might need to define authentication when building images. Authentication to a container registry is the most common one, but also users might have the need to define authentications for pulling source-code from Git. Overall, the authentication is done via the definion of [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) in which the require sensitive data will be stored.
25+
26+
## Build Secrets Annotation
27+
28+
Users need to add an annotation `build.build.dev/referenced.secret: "true"` to a build secret so that build controller can decide to take a reconcile action when a secret event (`create`, `update` and `delete`) happens. Below is a secret example with build annotation:
29+
30+
```yaml
31+
apiVersion: v1
32+
data:
33+
.dockerconfigjson: xxxxx
34+
kind: Secret
35+
metadata:
36+
annotations:
37+
build.build.dev/referenced.secret: "true"
38+
name: secret-docker
39+
type: kubernetes.io/dockerconfigjson
40+
```
41+
42+
This annotation will help us filter secrets which are not referenced on a Build instance. That means if a secret doesn't have this annotation, then although event happens on this secret, Build controller will not reconcile. Being able to reconcile on secrets events allow the Build controller to re-trigger validations on the Build configuration, allowing users to understand if a dependency is missing.
43+
44+
If you are using `kubectl` command create secrets, then you can first create build secret using `kubectl create secret` command and annotate this secret using `kubectl annotate secrets`. Below is an example:
45+
46+
```sh
47+
kubectl -n ${namespace} create secret docker-registry example-secret --docker-server=${docker-server} --docker-username="${username}" --docker-password="${password}" [email protected]
48+
kubectl -n ${namespace} annotate secrets example-secret build.build.dev/referenced.secret='true'
49+
```
2450

2551
## Authentication for Git
2652

@@ -44,6 +70,7 @@ metadata:
4470
annotations:
4571
tekton.dev/git-0: github.com
4672
tekton.dev/git-1: gitlab.com
73+
build.build.dev/referenced.secret: "true"
4774
type: kubernetes.io/ssh-auth
4875
data:
4976
ssh-privatekey: <base64 <~/.ssh/id_rsa>
@@ -64,6 +91,7 @@ metadata:
6491
annotations:
6592
tekton.dev/git-0: https://github.com
6693
tekton.dev/git-1: https://gitlab.com
94+
build.build.dev/referenced.secret: "true"
6795
type: kubernetes.io/basic-auth
6896
stringData:
6997
username: <cleartext username>
@@ -118,6 +146,7 @@ kubectl --namespace <YOUR_NAMESPACE> create secret docker-registry <CONTAINER_RE
118146
--docker-username=<USERNAME> \
119147
--docker-password=<PASSWORD> \
120148
149+
kubectl --namespace <YOUR_NAMESPACE> annotate secrets <CONTAINER_REGISTRY_SECRET_NAME> build.build.dev/referenced.secret='true'
121150
```
122151

123152
_Notes:_ When generating a secret to access docker hub, the `REGISTRY_HOST` value should be `https://index.docker.io/v1/`, the username is the Docker ID.

0 commit comments

Comments
 (0)