Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/services/jenkins: Introduce declarative credentials management #121958

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Pamplemousse
Copy link
Member

Signed-off-by: Pamplemousse xav.maso@gmail.com

Motivation for this change

Allow declarative management of credentials for Jenkins!
Depends on #121841 (I included its commits in this PR for the .credentials option to be reviewable - work).

There is a plugin to manage credentials: https://plugins.jenkins.io/credentials/. Useful to get stuff from SCMs, sign releases, and so on.

This my first "real" contribution to the nixos/modules side of things.
In particular, I took a very naive approach regarding the management of "secrets", which might be insecure:

  • Created credentials content lies in a file /var/lib/jenkins/credentials/<ID>/credentials.xml
    (However, the jenkins user already has means to read/write the content of credentials through the API anyway - i.e. I don't think this is effectively widening the attack surface.);
  • I am not too sure how much of it is put into the /nix/store either.

Also, as is, here are known limitations:

  • It only manages credentials for the system user (jenkins by default);
  • It only manages credentials for the "(global)" scope;
  • It only manages Username / Password credentials (but not other credentials types);
  • It relies on the https://plugins.jenkins.io/credentials/ plugin to be installed, but as jenkinsPlugins2nix is broken, I did not know how to add it to the configuration...

I had to start somewhere, and because it's somewhat my first time in this area of the repo, I was not shooting for a "perfect" solution.

Feedback appreciated! 🙏

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
    Signed-off-by: Pamplemousse xav.maso@gmail.com

@Pamplemousse Pamplemousse changed the title jenkins: Create the jenkins-cli command nixos/services/jenkins: Manage credentials declaratively May 6, 2021
@Pamplemousse Pamplemousse changed the title nixos/services/jenkins: Manage credentials declaratively nixos/services/jenkins: Introduce declarative credentials management May 6, 2021
Signed-off-by: Pamplemousse <xav.maso@gmail.com>
@stale
Copy link

stale bot commented Jan 3, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 3, 2022
@bjornfor
Copy link
Contributor

Related: I came across https://www.jenkins.io/projects/jcasc/ (Jenkins Configuration as Code) today. It creates a bit of a bootstrap issue, as you need to first install the plugin (jenkinsPlugins2Nix is not broken now btw), but seems to help making Jenkins setups more declarative.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 28, 2022
@bjornfor
Copy link
Contributor

Related: I came across https://www.jenkins.io/projects/jcasc/ (Jenkins Configuration as Code) today.

Of course, it turns out to not be truly declarative -- it supports adding and changing settings, but not removing 😢


config = mkIf (jenkinsCfg.enable && cfg.enable) {
assertions = [
{ assertion = jenkinsCfg.withCLI;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having this assertion that withCLI must be true, you can use an absolute path to the jenkins-cli program: ${pkgs.jenkins}/bin/jenkins-cli.

script =
let
_jenkinsCLI = {
auth = "-auth admin:\"$(cat ${jenkinsCfg.home}/secrets/initialAdminPassword)\"";
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Check that initialAdminPassword gets created if -Djenkins.install.runSetupWizard=false is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Check that initialAdminPassword gets created if -Djenkins.install.runSetupWizard=false is used.

It does not.

@bjornfor
Copy link
Contributor

There is a plugin to manage credentials: https://plugins.jenkins.io/credentials/. Useful to get stuff from SCMs, sign releases, and so on.

So this change depends on users having that plugin already installed? And currently that means imperatively installing the credentials plugin? Maybe we should get declarative plugin support in jenkins first?

@Pamplemousse
Copy link
Member Author

@bjornfor, indeed, as the description of the PR says:

It relies on the plugins.jenkins.io/credentials plugin to be installed, but as jenkinsPlugins2nix is broken, I did not know how to add it to the configuration...

@Pamplemousse
Copy link
Member Author

Thanks for taking interest in this PR by the way @bjornfor :)
As you might have seen, this has been in there for a while. TBH, I've somewhat lost interest in Jenkins since then. Not to mention that this PR gathered no interest since two weeks ago...

@bjornfor
Copy link
Contributor

@bjornfor, indeed, as the description of the PR says:

Sorry I missed that.

Should we mark this PR as a draft?

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants