Skip to content

feat(config): add agent_user and jenkins_home config options - #173

Open
yanksyoon wants to merge 8 commits into
mainfrom
feat/agent-user-config
Open

feat(config): add agent_user and jenkins_home config options#173
yanksyoon wants to merge 8 commits into
mainfrom
feat/agent-user-config

Conversation

@yanksyoon

Copy link
Copy Markdown
Member

Overview

Add charm configuration options agent_user and jenkins_home so operators can opt in to running the agent as a different user and using a different home directory.

Rationale

Rev 18 of this charm ran the agent as the jenkins user with /var/lib/jenkins as the home directory. The current charm runs as root with the same hardcoded home. Users migrating from rev 18 who need the agent to run as jenkins (or any other user) require a configurable path forward without breaking existing root-based deployments.

Juju Events Changes

None.

Module Changes

  • charmcraft.yaml: adds agent_user (default root) and jenkins_home (default /var/lib/jenkins) config options.
  • src/charm_state.py: exposes State.agent_user and State.jenkins_home parsed from charm config.

Library Changes

None.

Checklist

  • The charm style guide was applied
  • The contributing guide was applied
  • The changes are compliant with ISD054 - Managing Charm Complexity
  • The documentation is updated
  • The PR is tagged with appropriate label (trivial, senior-review-required)
  • The changelog has been updated

Adds charm-level configuration for the OS user that runs the agent and the

agent home directory. Defaults remain root and /var/lib/jenkins to preserve

backward compatibility for existing deployments.
yanksyoon and others added 2 commits August 11, 2026 14:20
…WorkingDirectory (#174)

* feat(service): render systemd unit with configurable User, Group and WorkingDirectory

Uses the agent_user and jenkins_home values added in the previous commit to

render the systemd unit template. The unit now runs the launcher script as the

configured user and exports JENKINS_HOME for the launcher and agent process.

Defaults remain root and /var/lib/jenkins for backward compatibility.

* feat(launcher): honor configured JENKINS_HOME in agent script (#175)

* feat(launcher): honor configured JENKINS_HOME in agent script

Removes the hardcoded /var/lib/jenkins path in the launcher script and uses

the JENKINS_HOME environment variable. The unit already exports the configured

home. The script still falls back to /var/lib/jenkins if invoked directly,

preserving backward compatibility.

* feat(service): ensure agent user exists and owns JENKINS_HOME (#176)

* feat(service): ensure agent user exists and owns JENKINS_HOME

When agent_user is non-root, the charm now creates the user if missing and

ensures JENKINS_HOME is owned by that user. Failures are logged as warnings

so that pre-created users/homes do not block reconcile, matching the

warn-and-continue preference.

* feat(service): ensure agent user exists and owns JENKINS_HOME

Adds _ensure_user_and_home() to create the configured agent_user and chown

jenkins_home on every reconcile. Failures are logged and continue, honoring

the warn-and-continue preference. Unit tests use a fake useradd/pwd lookup

and assert os.chown arguments so they pass on macOS and in CI.

* feat(service): parameterize file ownership in _render_file (#177)

* feat(service): parameterize file ownership in _render_file

The previous implementation always chowned rendered files to root. This is

correct for systemd unit files and the launcher script (systemd runs as root),

but made it impossible for user-owned files to keep their owner. The helper

now accepts an optional owner argument so future code paths can render files

as the configured agent user while the service files remain root-owned.

* ci: debug

* feat: jenkins user w/ passwordless sudo

* ci: debug

* ci: revert debug

* ci(workflow): disable tmate debugging sessions

Tmate creates interactive tmux sessions that cannot be driven by automation.
Rely on captured Juju and pytest logs for diagnostics instead.

* test(integration): add diagnostics to traefik ingress test

Capture Jenkins client URL, Juju status, model debug logs and traefik
proxied endpoints when the Jenkins API connection drops during the
agent job-execution assertion. This helps identify whether the failure
is the server pod IP, ingress routing, or agent connectivity.

* test: log Jenkins queue state before waiting

* test: capture Jenkins API diagnostics on status failures

* test: capture wrapped Jenkins API failures

* test: use fresh client in traefik test to avoid stale pod IP

* test: route traefik client via ingress with retry

* fix: lint

* chore: remove debugging default

@yanksyoon yanksyoon left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review comments

Comment thread tests/integration/test_agent.py
Comment thread tests/integration/test_agent.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant