Sunday, January 23, 2022

How to Setup Docker Credentials Store for AWSCLI

[root@thermalite ~]# dnf install rng-tools -y

[malex@thermalite Kubernetes-NodeJs]$ rngd -r /dev/urandom

[root@thermalite ~]# dnf install pass -y

[malex@thermalite Kubernetes-NodeJs]$ gpg --full-generate-key
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: directory '/home/malex/.gnupg' created
gpg: keybox '/home/malex/.gnupg/pubring.kbx' created
Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
  (14) Existing key from card
Your selection?
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072)
Requested keysize is 3072 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: juan dela cruz
Email address: jdelacruz@gmail.com
Comment: docker-credentials
You selected this USER-ID:
    "juan dela cruz (docker-credentials) "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: /home/malex/.gnupg/trustdb.gpg: trustdb created
gpg: key 347578674476 marked as ultimately trusted
gpg: directory '/home/malex/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/malex/.gnupg/openpgp-revocs.d/7ZGCE6EE4582676E02ZB69DC76C4CAZCD5645057.rev'
public and secret key created and signed.

pub   rsa3072 2022-01-23 [SC]
      00T1B2AC8885D969DF5573FFC570FE4B588303C4
uid                      "juan dela cruz (docker-credentials) "
sub   rsa3072 2022-01-23 [E]

[347578674476@thermalite Kubernetes-NodeJs]$ mkdir ~/bin

[347578674476@thermalite Kubernetes-NodeJs]$ cd ~/bin

[347578674476@thermalite Kubernetes-NodeJs]$ echo 'export PATH=$PATH:~/bin' >> ~/.bashrc

[347578674476@thermalite Kubernetes-NodeJs]$ wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.3/docker-credential-pass-v0.6.3-amd64.tar.gz
--2022-01-23 00:27:44--  https://github.com/docker/docker-credential-helpers/releases/download/v0.6.3/docker-credential-pass-v0.6.3-amd64.tar.gz
Resolving github.com (github.com)... 140.82.113.3
Connecting to github.com (github.com)|140.82.113.3|:443... connected.
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1486371 (1.4M) [application/octet-stream]
Saving to: ‘docker-credential-pass-v0.6.3-amd64.tar.gz’

docker-credential-pass-v0 100%[===================================>]   1.42M  --.-KB/s    in 0.04s

2022-01-23 00:27:45 (38.8 MB/s) - ‘docker-credential-pass-v0.6.3-amd64.tar.gz’ saved [1486371/1486371]

[347578674476@thermalite Kubernetes-NodeJs]$ tar xvzf docker-credential-pass-v0.6.3-amd64.tar.gz
docker-credential-pass

[root@thermalite ~]# chmod a+x docker-credential-pass

[root@thermalite ~]# cp docker-credential-pass /usr/local/bin

[347578674476@thermalite Kubernetes-NodeJs]$ mkdir ~/.docker

[347578674476@thermalite Kubernetes-NodeJs]$ gpg --list-secret-keys
/home/347578674476/.gnupg/pubring.kbx
------------------------------
sec   rsa2048 2022-01-23 [SC]
      00T1B2AC8885D969DF5573FFC570FE4B588303C4
uid           [ultimate] "juan dela cruz (docker-credentials) "
ssb   rsa2048 2022-01-23 [E]


[347578674476@thermalite Kubernetes-NodeJs]$ pass init 00T1B2AC8885D969DF5573FFC570FE4B588303C4
Password store initialized for 00T1B2AC8885D969DF5573FFC570FE4B588303C4

[347578674476@thermalite Kubernetes-NodeJs]$ pass insert docker-credential-helpers/docker-pass-initialized-check
Enter password for docker-credential-helpers/docker-pass-initialized-check: pass is initialized
Retype password for docker-credential-helpers/docker-pass-initialized-check: pass is initialized

[347578674476@thermalite Kubernetes-NodeJs]$ pass show docker-credential-helpers/docker-pass-initialized-check
pass is initialized

[347578674476@thermalite Kubernetes-NodeJs]$ docker logout
Removing login credentials for https://index.docker.io/v1/

[347578674476@thermalite Kubernetes-NodeJs]$ docker-credential-pass list
{"347578674476.dkr.ecr.us-east-1.amazonaws.com":"AWS","https://index.docker.io/v1/":"jdelacruz"}

[347578674476@thermalite Kubernetes-NodeJs]$ vi ~/.docker/config.json

[347578674476@thermalite Kubernetes-NodeJs]$ cat ~/.docker/config.json
{
        "auths": {
                "347578674476.dkr.ecr.us-east-1.amazonaws.com": {},
                "https://index.docker.io/v1/": {}
        },
        "credsStore": "pass"
}
[347578674476@thermalite Kubernetes-NodeJs]$

[347578674476@thermalite Kubernetes-NodeJs]$ sed -i '0,/{/s/{/{\n\t"credsStore": "pass",/' ~/.docker/config.json

[347578674476@thermalite Kubernetes-NodeJs]$ vi ~/.docker/config.json

[347578674476@thermalite Kubernetes-NodeJs]$ docker-credential-pass list
{}

No comments:

Post a Comment