diff options
| author | Mark Goddard <mark@stackhpc.com> | 2019-03-25 11:39:41 +0000 |
|---|---|---|
| committer | Mark Goddard <mark@stackhpc.com> | 2019-04-03 08:48:00 +0000 |
| commit | 8c4ab41ffa502a58714819e0407f3c17e6fde7d0 (patch) | |
| tree | 8a6d4ac2aef796027978c933f3b7750c60f8140d /tests/check-config.sh | |
| parent | a4bb8567da3e0e1468d66048c5b46cdeefcb1332 (diff) | |
| download | kolla-ansible-8c4ab41ffa502a58714819e0407f3c17e6fde7d0.tar.gz kolla-ansible-8c4ab41ffa502a58714819e0407f3c17e6fde7d0.zip | |
Check configuration file permissions in CI
Typically, non-executable files should have 660 or 600 and executable
files and directories should have 770. All should be owned by the
'config_owner_user' and 'config_owner_group' variables.
This change adds a script to check the owner and permissions of config
files under /etc/kolla, and runs it at the end of CI jobs.
Change-Id: Icdbabf36e284b9030017a0dc07b9dc81a37758ab
Related-Bug: #1821579
Diffstat (limited to 'tests/check-config.sh')
| -rwxr-xr-x | tests/check-config.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/check-config.sh b/tests/check-config.sh new file mode 100755 index 000000000..92d4f2c59 --- /dev/null +++ b/tests/check-config.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Check the generated configuration files. + +set -o errexit + +# Enable unbuffered output for Ansible in Jenkins. +export PYTHONUNBUFFERED=1 + +function check_config { + # Check every file in /etc/kolla/*. + failed=0 + expected_user=${CONFIG_OWNER_USER:-root} + expected_group=${CONFIG_OWNER_GROUP:-root} + # Ignore files generated by Zuul. + for f in $(sudo find /etc/kolla \ + -not -regex /etc/kolla/config.* \ + -not -path /etc/kolla \ + -not -name admin-openrc.sh \ + -not -name globals.yml \ + -not -name header \ + -not -name inventory \ + -not -name kolla-build.conf \ + -not -name passwords.yml \ + -not -name passwords.yml.old \ + -not -name sources.list) + do + mode=$(sudo stat -c %a $f) + owner=$(sudo stat -c %U:%G $f) + if [[ -d $f ]]; then + # Directories should be 770. + if [[ $mode != "770" ]]; then + failed=1 + echo "ERROR: Unexpected permissions on directory $f. Got $mode, expected 770" + fi + else + # Files should be 600, 660 or 770. + if [[ ! $mode =~ ^(600|660|770)$ ]] ; then + failed=1 + echo "ERROR: Unexpected permissions on file $f. Got $mode, expected 770 or 660" + fi + fi + # Owner user & group should be the config owner, default root. + if [[ $owner != "$expected_user:$expected_group" ]]; then + failed=1 + echo "ERROR: Unexpected ownership on $f. Got $owner, expected $expected_user:$expected_group" + fi + done + return $failed +} + +check_config |
