0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

fix: Add credentials config verification

This commit is contained in:
onidoru 2024-01-31 18:30:54 +02:00 committed by Nikita K
parent aafb1a50ac
commit e7fdfa0bcc
6 changed files with 53 additions and 9 deletions

46
.github/workflows/verify-config.yaml vendored Normal file
View file

@ -0,0 +1,46 @@
name: "Verify Example Config Files"
# Validate all example config files are relevant and valid.
on:
push:
branches:
- main
pull_request:
branches: [main]
release:
types:
- published
permissions: read-all
jobs:
verify-config:
name: Verify Config Files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install go
uses: actions/setup-go@v5
with:
cache: false
go-version: 1.20.x
- name: Cache go dependencies
id: cache-go-dependencies
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-mod-
- name: Install go dependencies
if: steps.cache-go-dependencies.outputs.cache-hit != 'true'
run: |
cd $GITHUB_WORKSPACE
go mod download
- uses: ./.github/actions/setup-localstack
- name: run verify-config
run: |
cd $GITHUB_WORKSPACE
make verify-config

View file

@ -392,7 +392,7 @@ verify-config: _verify-config verify-config-warnings verify-config-commited
.PHONY: _verify-config
_verify-config: binary
rm -f output.txt
$(foreach file, $(wildcard examples/config-*), ./bin/zot-$(OS)-$(ARCH) verify $(file) 2>&1 | tee -a output.txt || exit 1;)
$(foreach file, $(filter-out examples/config-ldap-credentials.json, $(wildcard examples/config-*)), ./bin/zot-$(OS)-$(ARCH) verify $(file) 2>&1 | tee -a output.txt || exit 1;)
.PHONY: verify-config-warnings
verify-config-warnings: _verify-config

View file

@ -225,14 +225,14 @@ authentication:
"startTLS":false,
"baseDN":"ou=Users,dc=example,dc=org",
"userAttribute":"uid",
"bindDN":"cn=ldap-searcher,ou=Users,dc=example,dc=org",
"bindPassword":"ldap-searcher-password",
"credentialsFile": "config-ldap-credentials.json",
"skipVerify":false,
"subtreeSearch":true
},
```
NOTE: When both htpasswd and LDAP configuration are specified, LDAP authentication is given preference.
NOTE: The separate file for storing DN and password credentials must be created. You can see example in `examples/config-ldap-credentials.json` file.
**OAuth2 authentication** (client credentials grant type) support via _Bearer Token_ configured with:

View file

@ -18,8 +18,7 @@
"startTLS": false,
"baseDN": "ou=Users,dc=example,dc=org",
"userAttribute": "uid",
"bindDN": "cn=ldap-searcher,ou=Users,dc=example,dc=org",
"bindPassword": "ldap-searcher-password",
"credentialsFile": "examples/config-ldap-credentials.json",
"skipVerify": false,
"subtreeSearch": true
},

View file

@ -8,8 +8,7 @@ http:
ldap:
address: ldap.example.org
basedn: ou=Users,dc=example,dc=org
binddn: cn=ldap-searcher,ou=Users,dc=example,dc=org
bindpassword: ldap-searcher-password
credentialsFile: examples/config-ldap-credentials.json
port: 389
skipverify: false
starttls: false

View file

@ -861,8 +861,8 @@ func readLDAPCredentials(ldapConfigPath string) (config.LDAPCredentials, error)
var ldapCredentials config.LDAPCredentials
if err := viperInstance.Unmarshal(&ldapCredentials); err != nil {
log.Error().Err(err).Msg("failed to unmarshal new config")
if err := viperInstance.UnmarshalExact(&ldapCredentials); err != nil {
log.Error().Err(err).Msg("failed to unmarshal ldap credentials config")
return config.LDAPCredentials{}, err
}