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

examples credentials ocmconfig #323

Merged
merged 40 commits into from
Sep 16, 2024
Merged
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9c4a434
examples credentials ocmconfig
ikhandamirov Sep 6, 2024
e64274f
update
ikhandamirov Sep 6, 2024
998c8a2
Merge branch 'main' into examples-creds-ocmconfig
ikhandamirov Sep 9, 2024
f312f6c
accessing several systems
ikhandamirov Sep 9, 2024
430023e
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 10, 2024
7252cb7
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 10, 2024
d696304
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 10, 2024
cb47a79
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 10, 2024
7eb3ca4
`password` better explained
ikhandamirov Sep 10, 2024
68ce05c
npm and maven
ikhandamirov Sep 12, 2024
7aa57c4
chapter
ikhandamirov Sep 13, 2024
79ec4b0
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 13, 2024
ed9a172
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 13, 2024
c0de841
Update content/docs/examples/creds-in-ocmconfig.md
ikhandamirov Sep 13, 2024
5b34d95
oci registries re-worked
ikhandamirov Sep 13, 2024
995822b
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
2d2c242
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
ace4926
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
3709e12
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
85d0e44
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
72d133e
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
03034b6
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
02f9575
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
8f398a2
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
c083080
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
67b0d0c
Merge branch 'main' into examples-creds-ocmconfig
morri-son Sep 16, 2024
f34cf28
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
1c1c950
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
eb490ff
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
6224a95
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
1d99d7c
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
fa98f36
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
d24b570
Update content/docs/examples/creds-in-ocmconfig.md
morri-son Sep 16, 2024
d7ada21
remove empty lines
morri-son Sep 16, 2024
da44ff0
Update creds-in-ocmconfig.md
morri-son Sep 16, 2024
d8875bf
Update creds-in-ocmconfig.md
morri-son Sep 16, 2024
7c97712
blank line before lists
ikhandamirov Sep 16, 2024
57528ce
exceptions for spell checker
ikhandamirov Sep 16, 2024
b657b73
port number w/o quotes
ikhandamirov Sep 16, 2024
7cafcab
sign empty commit
ikhandamirov Sep 16, 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
169 changes: 169 additions & 0 deletions content/docs/examples/creds-in-ocmconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
---
title: "Credentials in ocmconfig file"
morri-son marked this conversation as resolved.
Show resolved Hide resolved
description: ""
summary: ""
date: 2024-09-04T13:54:01+02:00
lastmod: 2024-09-04T13:54:01+02:00
draft: false
weight: 999
toc: true
---

## Overview

The [OCM command line client](https://github.com/open-component-model/ocm/blob/main/docs/reference/ocm.md) can be configured by supplying it with a [configuration file](https://github.com/open-component-model/ocm/blob/main/docs/reference/ocm_configfile.md). By default, the CLI looks for configuration in `$HOME/.ocmconfig`, if it exists.

The configuration file can be used in particular to specify the credentials, which are required for the CLI to be able to access the artifact repositories, referenced in CLI commands.
morri-son marked this conversation as resolved.
Show resolved Hide resolved

## Examples

This page contains basic examples of credentials configuration for a few most common artifact repository types. The examples below are complete `.ocmconfig` files, not snippets.

For comprehensive documentation on the credentials topic, including usage of certificates or HashiCorp Vault, execute the command `ocm credential-handling`.

### Repositories and Consumers

In the examples below some configuration is located under `configurations[0]`.`repositories`, and some other under `configurations[0]`.`consumers`. This chanpter explains the difference between `repositories` and `consumers`, which is potentially not as obvious as one could think.
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
frewilhelm marked this conversation as resolved.
Show resolved Hide resolved

In this context, `repository` is a place, where credentials can be stored, i.e. it is a credentials repository. For example, Docker's `config.json` can store multiple credentials, and in that sense the file serves as a repository that can store and provide credentials. That is why its location is configured under `repositories`. Other examples of credentials repositories can be the NPM's `.npmrc` file or a HashiCorp Vault instance.
morri-son marked this conversation as resolved.
Show resolved Hide resolved

A `consumer` is something the credentials are required for. For example, if you need to configure credentials that are required to log in to an OCI registry, one could say that the registry will be consuming these credentials, i.e. the registry is a credentials consumer. That is why it is configured under `consumers`.
morri-son marked this conversation as resolved.
Show resolved Hide resolved

### Re-use credentials configured for Docker
morri-son marked this conversation as resolved.
Show resolved Hide resolved

This `.ocmconfig` file will tell OCM CLI to use configuration from Docker's `config.json`.

```yaml
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
repositories:
- repository:
type: DockerConfig/v1
dockerConfigFile: "~/.docker/config.json"
propagateConsumerIdentity: true
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
```

### Accessing OCI registries
morri-son marked this conversation as resolved.
Show resolved Hide resolved

#### HTTPS and path
morri-son marked this conversation as resolved.
Show resolved Hide resolved

To access artifacts in `https://ghcr.io/mandelsoft`:
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
* Omit the protocol
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
* The path behind the top-level domain hast to be specified in a separate `pathprefix` field
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved

```yaml
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
consumers:
- identity:
type: OCIRegistry
hostname: ghcr.io
pathprefix: mandelsoft
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
credentials:
- type: Credentials
properties:
username: some-user
password: some-token
```

#### HTTP, port number, empty path
morri-son marked this conversation as resolved.
Show resolved Hide resolved

To access artifacts in `http://127.0.0.1:5001`:
* Omit the protocol
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
* Omit the port number
* As the URL has no path behind the port number, `pathprefix` element can be removed or left empty

```yaml
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
consumers:
- identity:
type: OCIRegistry
hostname: 127.0.0.1
credentials:
- type: Credentials
properties:
username: admin
password: admin
```

### Accessing Helm chart repositories
morri-son marked this conversation as resolved.
Show resolved Hide resolved

Similar to OCI registries, but use `HelmChartRepository` as identity type.

```yaml
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
consumers:
- identity:
type: HelmChartRepository
hostname: ghcr.io
pathprefix: mandelsoft
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
credentials:
- type: Credentials
properties:
username: some-user
password: some-token
```

### Accessing GitHub repositories
morri-son marked this conversation as resolved.
Show resolved Hide resolved

To access code in `https://my.github.enterprise/my-org/my-repo`:
* Use `Github` as identity type
* `hostname` is the domain name of the GitHub instance
* `pathname` is a combination of organization and repository names
* `token` is a personal access token generated in GitHub Developer Settings

```yaml
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
consumers:
- identity:
type: Github
hostname: my.github.enterprise
pathprefix: my-org/my-repo
credentials:
- type: Credentials
properties:
token: ghp_my_personal_access_token
```

### Accessing several systems
morri-son marked this conversation as resolved.
Show resolved Hide resolved

It is, of course, possible to configure credentials for several systems in the same `.ocmconfig` file. To do that, you can combine as many repositories and consumers as you need.

The example below instructs OCM CLI to look for credentials in Docker's `config.json`, and in addition specifies dedicated credentials for an OCI registry and a GitHub repository.

```yaml
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
repositories:
- repository:
type: DockerConfig/v1
dockerConfigFile: "~/.docker/config.json"
propagateConsumerIdentity: true
consumers:
- identity:
type: OCIRegistry
hostname: ghcr.io
pathprefix: mandelsoft
ikhandamirov marked this conversation as resolved.
Show resolved Hide resolved
credentials:
- type: Credentials
properties:
username: some-user
password: some-token
- identity:
type: Github
hostname: my.github.enterprise
pathprefix: my-org/my-repo
credentials:
- type: Credentials
properties:
token: ghp_my_personal_access_token
```