-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authentication to utility registry (#144)
Signed-off-by: Jeff McCoy <[email protected]>
- Loading branch information
1 parent
e70d05f
commit 0c85a33
Showing
30 changed files
with
345 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/docker/cli/cli/config" | ||
"github.com/docker/cli/cli/config/types" | ||
"github.com/google/go-containerregistry/pkg/authn" | ||
"github.com/google/go-containerregistry/pkg/name" | ||
"log" | ||
"os" | ||
) | ||
// Login adds the given creds to the user's Docker config, usually located at $HOME/.docker/config.yaml. It does not try | ||
// to connect to the given registry, it just simply adds another entry to the config file. | ||
// This function was mostly adapted from https://github.com/google/go-containerregistry/blob/5c9c442d5d68cd96787559ebf6e984c7eb084913/cmd/crane/cmd/auth.go | ||
func Login(serverAddress string, user string, password string) error { | ||
cf, err := config.Load(os.Getenv("DOCKER_CONFIG")) | ||
if err != nil { | ||
return err | ||
} | ||
creds := cf.GetCredentialsStore(serverAddress) | ||
if serverAddress == name.DefaultRegistry { | ||
serverAddress = authn.DefaultAuthKey | ||
} | ||
if err := creds.Store(types.AuthConfig{ | ||
ServerAddress: serverAddress, | ||
Username: user, | ||
Password: password, | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
if err := cf.Save(); err != nil { | ||
return err | ||
} | ||
log.Printf("logged in via %s", cf.Filename) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/crypto/bcrypt" | ||
) | ||
|
||
// GetHtpasswdString converts a username and password to a properly formatted and hashed format for `htpasswd` | ||
func GetHtpasswdString(username string, password string) (string, error) { | ||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) | ||
if err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("%s:%s", username, hash), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
type: kubernetes.io/dockerconfigjson | ||
metadata: | ||
name: private-registry | ||
namespace: demo | ||
stringData: | ||
.dockerconfigjson: | | ||
{ | ||
"auths": { | ||
"registry.dso.mil": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"registry1.dso.mil": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"docker.io": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"registry-1.docker.io": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"ghcr.io": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
type: kubernetes.io/dockerconfigjson | ||
metadata: | ||
name: private-registry | ||
namespace: default | ||
stringData: | ||
.dockerconfigjson: | | ||
{ | ||
"auths": { | ||
"registry.dso.mil": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"registry1.dso.mil": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"docker.io": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"registry-1.docker.io": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
}, | ||
"ghcr.io": { | ||
"auth":"###ZARF_DOCKERAUTH###" | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.