Skip to content
README.md 2.47 KiB
Newer Older
Ivan Artiukhov's avatar
Ivan Artiukhov committed
# Credentials
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
> Component to set the credentials for external hosts
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Getting Started
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Include the following in `.gitlab-ci.yml`:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
include:
  - component: "gitlab.arm.com/ci/component/credentials@<version>"
    inputs:
      stage: build
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
checkout-job:
  extends: .credentials
Ivan Artiukhov's avatar
Ivan Artiukhov committed
```

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Purpose
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Some projects need to have an access to external repositories which needs specific credentials to read data.
.credentials allows to set those up through CI/CD variables with no need to hardcode or injecting secure data into the
project repository.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
`.credentials` allows to set those up through CI/CD variables with no need to hardcode or injecting secure data into the
project repository.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Usage
```yaml
include: 
  - component: "gitlab.arm.com/ci/component/credentials@<version>"

  # Checkout external repository
  checkout:
    extends: .credentials
    image: debian:bookworm
    variables:
      TEST_SERVER_USERNAME: $TEST_SERVER_USERNAME
      TEST_SERVER_HOSTNAME: $TEST_SERVER_HOSTNAME
    script: 
      - echo "Completed credentials setup"
      - echo "Testing SSH connection"
      - ssh $TEST_SERVER_USERNAME@$TEST_SERVER_HOSTNAME 'ls'
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
### Configuration
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Configuration is done with CI/CD variables of `file` type.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `SSH_KEYS`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The file containing private keys to be injected to `ssh-agent` in a format:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
> **Note:** A trailing newline is required at the end of the variable.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```
-----BEGIN OPENSSH PRIVATE KEY-----
<KEY 1 DATA>
-----END OPENSSH PRIVATE KEY-----
-----BEGIN OPENSSH PRIVATE KEY-----
<KEY 2 DATA>
-----END OPENSSH PRIVATE KEY-----
-----BEGIN OPENSSH PRIVATE KEY-----
<KEY n DATA>
-----END OPENSSH PRIVATE KEY-----
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `SSH_CONFIG`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The SSH config file containing profiles for different host configurations to be set in `~/.ssh/config` file.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```
Host gerrit.secret.project.com
        User username
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `SSH_KEYSCAN`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The file containing the public keys of the accessed hosts to be set in `~/.ssh/known_hosts` file.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
To generate a file for the hosts that the CI will connect to:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```sh
ssh-keyscan -p 22 gerrit.secret.project.com > /tmp/known_hosts
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Add the contents of `/tmp/known_hosts` to the `SSH_KEYSCAN` variable in the GitLab CI/CD settings.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
#### `NETRC`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The file with login and initialization information to be set in `~/.netrc` file.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
GitLab CI/CD files can re-use variables:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```
machine $ARTIFACTORY_HOST
login $ARTIFACTORY_USERNAME
password $ARTIFACTORY_PASSWORD
```
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Where `ARTIFACTORY_*` variables are normal CI/CD variables in the GitLab CI/CD settings.