Skip to content
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

Adding Porch private authenticated registries functionality documentation #178

Merged
merged 21 commits into from
Nov 7, 2024
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6c14729
added documentation for setting up function runner to use private aut…
Catalin-Stratulat-Ericsson Oct 21, 2024
3c10cdb
modification to language, hyperlinks and improved consistency
Catalin-Stratulat-Ericsson Oct 21, 2024
240014b
small patch for secret name variable
Catalin-Stratulat-Ericsson Oct 21, 2024
a8562b4
added small statement regarding potential access permission issues
Catalin-Stratulat-Ericsson Oct 22, 2024
cb9cd33
added example for mount path permissions
Catalin-Stratulat-Ericsson Oct 22, 2024
119236b
fix typo in first point
Catalin-Stratulat-Ericsson Oct 22, 2024
b79522b
added namespace clarification
Catalin-Stratulat-Ericsson Oct 22, 2024
9907d33
changed symbol type for file names as per suggestion
Catalin-Stratulat-Ericsson Oct 22, 2024
eb97c98
changed e.g. usage to for example as per suggestions
Catalin-Stratulat-Ericsson Oct 22, 2024
13f9793
added note synax to notes as per recommendation
Catalin-Stratulat-Ericsson Oct 22, 2024
b9672d0
changed the Hugo Warnings to Notes
Catalin-Stratulat-Ericsson Oct 22, 2024
c681720
made ammendments to language and structure as per comment suggestions
Catalin-Stratulat-Ericsson Oct 29, 2024
34b062f
renamed file name to match the title change in previous commit
Catalin-Stratulat-Ericsson Oct 29, 2024
f8dc2d3
changed small formating issue
Catalin-Stratulat-Ericsson Oct 29, 2024
99d13cb
ammended requested changes which were missed
Catalin-Stratulat-Ericsson Oct 29, 2024
672afec
added docker config.json template explination for clarity
Catalin-Stratulat-Ericsson Oct 29, 2024
3e15fe1
fixed repeated here in link
Catalin-Stratulat-Ericsson Oct 29, 2024
3b272ee
fixed incorrect style use as per styling guide
Catalin-Stratulat-Ericsson Oct 29, 2024
777d91f
adding documentation to match new arguments
Catalin-Stratulat-Ericsson Nov 6, 2024
bed0059
added clarification of secret duplication to porch-fn-system namespace
Catalin-Stratulat-Ericsson Nov 6, 2024
aa7129e
fixed few grammatical errors as suggested by comments
Catalin-Stratulat-Ericsson Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: "Using authenticated private registries"
type: docs
weight: 4
description: ""
---

To enable the Porch function runner to pull kpt function images from authenticated private registries, the system requires:

1. Creating a kubernetes secret using a JSON file according to the Docker config schema, containing valid credentials for each authenticated registry.
2. Mounting this new secret as a volume on the function runner.
3. Providing the path of the mounted secret to the function runner using the argument `--registry-auth-secret-path`

An example template of what a docker *config.json* file looks like is as follows below. The base64 encoded value *bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=* of the *auth* key decodes to *my_username:my_password*, which is the format used by the config when authenticating.

```json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="
},
"ghcr.io": {
"auth": "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="
}
}
}
```

A quick way to generate this secret for your use using your docker *config.json* would be to run the following command:

```bash
kubectl create secret generic <SECRET_NAME> --from-file=.dockerconfigjson=/path/to/your/config.json --type=kubernetes.io/dockerconfigjson --dry-run=client -o yaml -n porch-system
```

{{% alert title="Note" color="primary" %}}
The secret must be in the same namespace as the function runner deployment. By default, this is the *porch-system* namespace.
{{% /alert %}}

This should generate a secret template, similar to the one below, which you can add to the *2-function-runner.yaml* file in the Porch catalog package found [here](https://github.com/nephio-project/catalog/tree/main/nephio/core/porch)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Catalin-Stratulat-Ericsson Secret generated like this kubectl create secret docker-registry XXXX --docker-server=https://index.docker.io/v1/ --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>

Should also work I suppose? That creates a .dockerconfigjson inside secrets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. So long as the content being put into the secret is in the JSON format and follows the docker config.json schema it should work just fine.
  2. One side note i will say regarding doing it that way is that you would be leaving your password/token in plaintext in the terminal and also in the history of the machine which i don't believe should be encouraged or used as the preferred way to create the secret in the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I agree with the second point but we can always remove it from the history using history -d <line-number>

```yaml
apiVersion: v1
data:
.dockerconfigjson: <base64-encoded-data>
kind: Secret
metadata:
creationTimestamp: null
name: <SECRET_NAME>
namespace: porch-system
type: kubernetes.io/dockerconfigjson
```

Next you must mount the secret as a volume on the function runner deployment. Add the following snippet to the Deployment object in the *2-function-runner.yaml* file:

```yaml
volumeMounts:
- mountPath: /pod-cache-config
name: pod-cache-config-volume
- mountPath: /var/tmp/auth-secret
name: docker-config
readOnly: true
volumes:
- name: pod-cache-config-volume
configMap:
name: pod-cache-config
- name: docker-config
secret:
secretName: <SECRET_NAME>
```

You may specify your desired `mountPath:` so long as the function runner can access it.

{{% alert title="Note" color="primary" %}}
The chosen `mountPath:` should use its own, dedicated sub-directory, so that it does not overwrite access permissions of the existing directory. For example, if you wish to mount on `/var/tmp` you should use `mountPath: /var/tmp/<SUB_DIRECTORY>` etc.
{{% /alert %}}

Lastly you must add the `--registry-auth-secret-path` to the arguments of the function-runner Deployment object in the *2-function-runner.yaml* file, giving the path of the secret file mount:

```yaml
command:
- /server
- --config=/config.yaml
- --registry-auth-secret-path=/var/tmp/auth-secret/.dockerconfigjson
- --functions=/functions
- --pod-namespace=porch-fn-system
```

With this last step, if your Porch package uses a custom kpt function image stored in an authenticated private registry (for example `- image: ghcr.io/private-registry/set-namespace:customv2`), the function runner will now use the secret info as an `imagePullSecret` for the function pods as documented [here](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/).