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

Git Token Based Authentication Documentation #221

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 0 additions & 37 deletions content/en/docs/porch/user-guides/adding-external-git-ca-bundle.md

This file was deleted.

117 changes: 117 additions & 0 deletions content/en/docs/porch/user-guides/git-authentication-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
title: "Git Authentication Configuration"
type: docs
weight: 4
description: ""
---

## 1. Porch Server to Git Interaction

The porch server handles interaction with associated git repositories through the use of porch repository CR (Custom Resource) which act as a link between the porch server and the git repositories the server is meant to interact with and store packages on.

More information on porch repositories can be found [here](../package-orchestration.md#repositories).

### 1.1 Porch Repository Basic Authentication Configuration

A porch repository object can be created through the use of the `porchctl repo reg porch-test-repository -n porch-test http://example-ip:example-port/repo.git --repo-basic-password=password --repo-basic-username=username` command which creates a secret and repository object.

The basic authentication secret must meet the following criteria:

- Exist in the same namespace as the Repository CR (Custom Resource) that requires it.
- Have a Data keys named *username* and *password* containing the relevant information.
- Be of type *basic-auth*.

Which would be the equivalent of doing a `kubectl apply -f` on a yaml file with the following content (assuming the porch-test namespace exists on the cluster):

```yaml
apiVersion: v1
kind: Secret
metadata:
name: git-auth-secret
namespace: porch-test
data:
password: base-64-encoded-password
username: base-64-encoded-username
type: kubernetes.io/basic-auth

---
apiVersion: config.porch.kpt.dev/v1alpha1
kind: Repository

metadata:
name: porch-test-repository
namespace: porch-test

spec:
description: porch test repository
content: Package
deployment: false
type: git
git:
repo: http://example-ip:example-port/repo.git
directory: /
branch: main
secretRef:
name: git-auth-secret
```

### 1.2 Porch Repository Token Authentication Configuration

The authentication to the git repository can be configured to be in token format by altering the secret used in the porch repository object.

The token authentication secret must meet the following criteria:

- Exist in the same namespace as the Repository CR (Custom Resource) that requires it
- Have a Data key named *token* containing the relevant git token information.
- Be of type *Opaque*.

For example:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: git-auth-secret
namespace: porch-test
data:
token: base-64-encoded-token
type: Opaque
```

{{% alert title="Note" color="primary" %}}
The Porch server caches the authentication credentials from the secret, so if the secret's contents are updated they may in fact not be the credentials which are used in the authentication until the old secret credentials are no longer valid which triggers the porch server to query the secret again use the new credentials which if valid become the new cached authentication values.
{{% /alert %}}

### 1.3 Porch Repository HTTPS Configuration

To enable the porch server to communicate with a custom git deployment over HTTPS, we must:

1. Provide an additional arguments flag `use-git-cabundle=true` to the porch-server deployment.
2. Provide an additional Kubernetes secret containing the relevant certificate chain in the form of a cabundle.

The secret itself must meet the following criteria:

- Exist in the same namespace as the Repository CR that requires it.
- Be named specifically \<namespace\>-ca-bundle.
- Have a Data key named *ca.crt* containing the relevant ca certificate (chain).

For example, a Git Repository is hosted over HTTPS at the *https://my-gitlab.com/joe.bloggs/blueprints.git* URL:

`https://my-gitlab.com/joe.bloggs/blueprints.git`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something needed to be typed to the terminal? If not please use ** to higlight it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my apologies. this section is from the previous documentation which was on this page before my changes, i presumed that since it was inside the documentation already it was fine as is and left it mostly untouched. ill make amends as suggested.


Before creating the new Repository in the **GitLab** namespace, we must create a secret that fulfils the criteria above.

`kubectl create secret generic gitlab-ca-bundle --namespace=gitlab --from-file=ca.crt`

Which would produce the following:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: gitlab-ca-bundle
namespace: gitlab
type: Opaque
data:
ca.crt: FAKE1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNuakNDQWdHZ0F3SUJB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