Gate local repo writes behind OIDC tokens
Add ARTIFACTAPI_AUTH_UPLOADS to require a verified token for local uploads, deletes, evictions, /api/v1 publishes and /v2 push. Accept the token as Bearer, Token, Basic password or bare header, and serve a Docker registry token endpoint so pulls stay anonymous.
This commit is contained in:
@@ -61,6 +61,8 @@ type Config struct {
|
||||
// Bearer-JWT auth on configuration writes; empty issuer disables it.
|
||||
OIDCIssuer string
|
||||
OIDCAudiences []string
|
||||
// AuthUploads extends that auth to local repo uploads, deletes and evictions.
|
||||
AuthUploads bool
|
||||
}
|
||||
|
||||
func (c *Config) DatabaseDSN() string {
|
||||
@@ -105,6 +107,13 @@ func Load() (*Config, error) {
|
||||
if oidcIssuer != "" && len(oidcAudiences) == 0 {
|
||||
return nil, fmt.Errorf("ARTIFACTAPI_OIDC_AUDIENCE is required when ARTIFACTAPI_OIDC_ISSUER is set")
|
||||
}
|
||||
authUploads, err := strconv.ParseBool(getenv("ARTIFACTAPI_AUTH_UPLOADS", "false"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid ARTIFACTAPI_AUTH_UPLOADS: %w", err)
|
||||
}
|
||||
if authUploads && oidcIssuer == "" {
|
||||
return nil, fmt.Errorf("ARTIFACTAPI_OIDC_ISSUER is required when ARTIFACTAPI_AUTH_UPLOADS is set")
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
ListenAddr: getenv("LISTEN_ADDR", ":8000"),
|
||||
@@ -142,6 +151,7 @@ func Load() (*Config, error) {
|
||||
|
||||
OIDCIssuer: oidcIssuer,
|
||||
OIDCAudiences: oidcAudiences,
|
||||
AuthUploads: authUploads,
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
|
||||
@@ -81,3 +81,23 @@ func TestLoadOIDC(t *testing.T) {
|
||||
t.Error("expected error for issuer without audience")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadAuthUploads(t *testing.T) {
|
||||
cfg, err := Load()
|
||||
if err != nil || cfg.AuthUploads {
|
||||
t.Fatalf("default: %v, AuthUploads=%v", err, cfg.AuthUploads)
|
||||
}
|
||||
t.Setenv("ARTIFACTAPI_AUTH_UPLOADS", "true")
|
||||
if _, err := Load(); err == nil {
|
||||
t.Error("expected error for AUTH_UPLOADS without issuer")
|
||||
}
|
||||
t.Setenv("ARTIFACTAPI_OIDC_ISSUER", "https://vault.example/v1/identity/oidc")
|
||||
t.Setenv("ARTIFACTAPI_OIDC_AUDIENCE", "artifactapi")
|
||||
if cfg, err := Load(); err != nil || !cfg.AuthUploads {
|
||||
t.Fatalf("enabled: %v, AuthUploads=%v", err, cfg.AuthUploads)
|
||||
}
|
||||
t.Setenv("ARTIFACTAPI_AUTH_UPLOADS", "maybe")
|
||||
if _, err := Load(); err == nil {
|
||||
t.Error("expected error for invalid ARTIFACTAPI_AUTH_UPLOADS")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user