Skip to content

Commit

Permalink
fix: Add credentials config verification
Browse files Browse the repository at this point in the history
  • Loading branch information
onidoru committed Feb 5, 2024
1 parent 4e33c17 commit b3035fa
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/verify-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,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
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 1 addition & 2 deletions examples/config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
3 changes: 1 addition & 2 deletions examples/config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check warning on line 865 in pkg/cli/server/root.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/server/root.go#L865

Added line #L865 was not covered by tests

return config.LDAPCredentials{}, err
}
Expand Down

0 comments on commit b3035fa

Please sign in to comment.