Skip to content

Extract setup-permissions.sh from install script#226

Open
lohdipak wants to merge 3 commits into
aws:mainfrom
lohdipak:main
Open

Extract setup-permissions.sh from install script#226
lohdipak wants to merge 3 commits into
aws:mainfrom
lohdipak:main

Conversation

@lohdipak

Copy link
Copy Markdown

Move user, group, and directory permission setup into a separate reusable script so it can be called independently by RPM post-install or other packaging workflows.

Description

Why is this change being made?

  1. To reuse the code in RPM build

What is changing?

  1. Move user, group, and directory permission setup into a separate reusable script

Related Links

  • Issue #, if available:

Testing

$ getent group awscreds
awscreds:x:1002:

$ getent group aws-wcp-token
aws-wcp-token:x:1003:aws-wcp

$ getent passwd aws-wcp
aws-wcp:x:992:1002::/opt/aws/workload-credentials-provider:/sbin/nologin

$ ls -ld /opt/aws/workload-credentials-provider
drwxr-xr-x. 4 aws-wcp root 29 Jun 20 18:17 /opt/aws/workload-credentials-provider

How was this tested?

sudo ./install 
Permissions setup complete.
Installed aws-workload-credentials-provider-token.service
Installed aws-workload-credentials-provider-sm.service
Installed aws-workload-credentials-provider-acm.service (with CAP_DAC_OVERRIDE)
No ACM configuration found or ACM is disabled, skipping permissions setup
Created symlink /etc/systemd/system/multi-user.target.wants/aws-workload-credentials-provider-token.service → /etc/systemd/system/aws-workload-credentials-provider-token.service.
Created symlink /etc/systemd/system/multi-user.target.wants/aws-workload-credentials-provider-sm.service → /etc/systemd/system/aws-workload-credentials-provider-sm.service.
Created symlink /etc/systemd/system/multi-user.target.wants/aws-workload-credentials-provider-acm.service → /etc/systemd/system/aws-workload-credentials-provider-acm.service.
Started services
Installation complete.
$ curl http://localhost:2773/ping
healthy

When testing locally, provide testing artifact(s):

  1. See above

Reviewee Checklist

Update the checklist after submitting the PR

  • [X ] I have reviewed, tested and understand all changes
    If not, why:
  • [X ] I have filled out the Description and Testing sections above
    If not, why:
  • [ X] Build and Unit tests are passing
    If not, why:
  • [ X] Unit test coverage check is passing
    If not, why:
  • Integration tests pass locally
    If not, why:
  • I have updated integration tests (if needed)
    If not, why: code refactor. no integ test change is required.
  • [ X] I have ensured no sensitive information is leaking (i.e., no logging of sensitive fields, or otherwise)
    If not, why:
  • [ X] I have added explanatory comments for complex logic, new classes/methods and new tests
    If not, why:
  • I have updated README/documentation (if needed)
    If not, why: NA
  • I have clearly called out breaking changes (if any)
    If not, why: NA

Reviewer Checklist

All reviewers please ensure the following are true before reviewing:

  • Reviewee checklist has been accurately filled out
  • Code changes align with stated purpose in description
  • Test coverage adequately validates the changes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Move user, group, and directory permission setup into a separate
reusable script so it can be called independently by RPM post-install
or other packaging workflows.
@lohdipak lohdipak requested a review from a team as a code owner June 20, 2026 18:31
@lohdipak lohdipak requested review from i-am-SR and simonmarty June 20, 2026 18:32
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.27%. Comparing base (f1e4cbd) to head (1e3c539).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #226   +/-   ##
=======================================
  Coverage   86.27%   86.27%           
=======================================
  Files          34       34           
  Lines        9331     9331           
  Branches     9331     9331           
=======================================
  Hits         8050     8050           
  Misses       1148     1148           
  Partials      133      133           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Directory permissions
#

mkdir -p "${PROVIDER_DIR}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do if this fails? https://linux.die.net/man/2/mkdir

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script has #!/bin/bash -e at the top, so any command failure (including mkdir) will cause the script to exit immediately with a non-zero status.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems ok with me but it's a bit inconsistent with the other operations here succeeding if the resource already exists. I think it's fine from a functional standpoint though.

simonmarty
simonmarty previously approved these changes Jun 22, 2026

groupadd -f "${PROVIDER_GROUP}"
groupadd -f "${TOKEN_GROUP}"
useradd -r -M -d "${PROVIDER_DIR}" -s /sbin/nologin -g "${PROVIDER_GROUP}" -G "${TOKEN_GROUP}" "${PROVIDER_USER}" || [ $? -eq 9 ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useradd ... || [ $? -eq 9 ] idempotency pattern only creates the user the first time. If the script is re-run, the user already exists (exit 9), and the -G "${TOKEN_GROUP}" supplementary group membership is silently NOT updated. If TOKEN_GROUP changes or the user predated this group, the membership won't be reconciled. Consider running usermod -aG "${TOKEN_GROUP}" "${PROVIDER_USER}" after the useradd to ensure group membership is correct on re-runs.

AI-generated, feedback may be incorrect

chmod 755 "${PROVIDER_DIR}"
chown "${PROVIDER_USER}" "${PROVIDER_DIR}"

echo "Permissions setup complete." No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing newline at end of file. Combined with echo -n-free output this is minor, but POSIX text files should end with a newline; some tools and linters will complain.

AI-generated, feedback may be incorrect


groupadd -f "${PROVIDER_GROUP}"
groupadd -f "${TOKEN_GROUP}"
useradd -r -M -d "${PROVIDER_DIR}" -s /sbin/nologin -g "${PROVIDER_GROUP}" -G "${TOKEN_GROUP}" "${PROVIDER_USER}" || [ $? -eq 9 ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the original explanatory comment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

i-am-SR
i-am-SR previously approved these changes Jun 22, 2026
Restore explanatory comment for useradd exit code 9 handling and add
trailing newline.
@lohdipak lohdipak dismissed stale reviews from i-am-SR and simonmarty via 1e3c539 June 23, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants