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/cfssl: Add new module for cfssl #44127

Merged
merged 1 commit into from Aug 3, 2018
Merged

Conversation

johanot
Copy link
Contributor

@johanot johanot commented Jul 26, 2018

  • based on module originally written by @srhb
  • complies with available options in cfssl v1.3.2
  • uid and gid 299 reserved in ids.nix
  • added simple nixos test case
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

@johanot
Copy link
Contributor Author

johanot commented Jul 26, 2018

@GrahamcOfBorg test cfssl

@srhb
Copy link
Contributor

srhb commented Jul 26, 2018

@johanot You need to have privileges in OfBorg for that.

@GrahamcOfBorg test cfssl

@GrahamcOfBorg
Copy link

Success on aarch64-linux

Attempted: tests.cfssl

No partial log is available.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: tests.cfssl

Partial log (click to expand)

machine: exit status 1
syncing
machine: running command: sync
machine: exit status 0
test script finished in 12.46s
cleaning up
killing machine (pid 597)
vde_switch: EOF on stdin, cleaning up and exiting
vde_switch: Could not remove ctl dir '/build/vde1.ctl': Directory not empty
/nix/store/8gklc39jal58cfjhzqb7qx6v0xgg1hxn-vm-test-run-cfssl


dataDir = mkOption {
default = "/var/lib/cfssl";
type = types.str;
Copy link
Member

Choose a reason for hiding this comment

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

Use types.path instead

in {
options.services.cfssl = {
enable = mkEnableOption ''
Whether to enable the CFSSL CA api-server.
Copy link
Member

Choose a reason for hiding this comment

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

Only use mkEnableOption "the CFSSL CA api-server" here, mkEnableOption adds the "Whether to enable" thing.


port = mkOption {
default = 8888;
type = types.int;
Copy link
Member

Choose a reason for hiding this comment

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

You could use the newish types.ints.u16 to prevent users trying to assign an invalid port (have seen people do this)

dataDir = mkOption {
default = "/var/lib/cfssl";
type = types.str;
description = "cfssl work directory";
Copy link
Member

Choose a reason for hiding this comment

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

All descriptions should end with a colon.

};

ca = mkOption {
default = "file:${cfg.dataDir}/ca.pem";
Copy link
Member

Choose a reason for hiding this comment

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

I think doing it like this would make the module system rebuild the man pages and stuff when somebody changes cfg.dataDir. Using defaultText = "file:\${cfg.dataDir}/ca.pem", removing the default = , and setting services.cfssl.ca = "file:${cfg.dataDir}/ca.pem"` in the config section at the bottom should fix that.

Same with the caKey option.


configFile = mkOption {
default = null;
type = types.nullOr types.str; # FIXME: types.nonStorePath, may contain secrets
Copy link
Member

Choose a reason for hiding this comment

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

I think it's the user's responsibility to know when secrets would end up in the nix store. There are also a lot of users for which that isn't much of a problem anyways because they encrypt their nix store and are the only users.

A warning in the description would be appropriate though. Same for the other options that have a FIXME.


responderKey = mkOption {
default = null;
type = types.nullOr types.str; # FIXME: types.nonStorePath, secret
Copy link
Member

Choose a reason for hiding this comment

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

types.path, same for tlsKey and dbConfig.

};

config = {
users.extraGroups."cfssl" = {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: cfssl doesn't need to be quoted, same with the one in users.extraUsers below.

systemd.services.cfssl = mkIf cfg.enable {
description = "CFSSL CA API server";
wantedBy = [ "multi-user.target" ];

Copy link
Member

Choose a reason for hiding this comment

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

Add after = [ "network.target" ]; here to prevent it from starting before the basic network stuff is working.

@johanot
Copy link
Contributor Author

johanot commented Jul 28, 2018

@infinisil Thanks for feedback! Will do the necessary changes Monday.

@johanot
Copy link
Contributor Author

johanot commented Jul 30, 2018

@infinisil please review: 16a3ed4 .. Keeping the commit separate for your convenience for now. Will squash if you approve the changes.

(opt "int-dir" intDir)
(opt "metadata" metadata)
(opt "remote" remote)
(opt "config" configFile)
Copy link
Member

@infinisil infinisil Jul 30, 2018

Choose a reason for hiding this comment

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

I only just saw this, how does this config option interact with the other args? Because if it can provide all these values, then it would make sense to have a configFile option allowing you to pass your own config file (which would be passed via --config if it's set), and fall back to a generated config file from all the other options. Only the --config arg would need to be passed in both cases.

Edit: This also allows the user to not store secrets in the store, as they can provide their own config somewhere out of /nix/store.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@infinisil I hear what you say. But the config file does not have the same options as the cmdline options. Ref: https://github.com/cloudflare/cfssl/blob/80d5f5b4cfe73f5a918b851f03d468eb28499131/config/config.go#L74

Unfortunately it's not well documented, but the config file contains an optional list of different profiles for CA-signing. While some flags overlap - like AuthConfig (remotes) and CN-constraints - others do not. Like Bind Address (only cmdline) and Cert content (expirty, constraints etc.) (only configfile).

@infinisil
Copy link
Member

@GrahamcOfBorg test cfssl

@GrahamcOfBorg
Copy link

Success on aarch64-linux

Attempted: tests.cfssl

No partial log is available.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: tests.cfssl

Partial log (click to expand)

machine: exit status 1
syncing
machine: running command: sync
machine: exit status 0
test script finished in 59.58s
cleaning up
killing machine (pid 597)
vde_switch: EOF on stdin, cleaning up and exiting
vde_switch: Could not remove ctl dir '/build/vde1.ctl': Directory not empty
/nix/store/3ai0zc5074np28x6gbhnb61kaklkj931-vm-test-run-cfssl

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

LGTM thanks, feel free to squash!

@johanot
Copy link
Contributor Author

johanot commented Aug 2, 2018

@infinisil Thanks! Squash done.

@infinisil
Copy link
Member

Oh wait, one minor thing: can you change the commit message to "nixos/cfssl: init"?

- based on module originally written by @srhb
- complies with available options in cfssl v1.3.2
- uid and gid 299 reserved in ids.nix
- added simple nixos test case
@johanot
Copy link
Contributor Author

johanot commented Aug 3, 2018

Done :)

@infinisil infinisil merged commit d31f89d into NixOS:master Aug 3, 2018
@infinisil
Copy link
Member

Awesome, thanks :)

@johanot johanot deleted the nixos-cfssl branch August 3, 2018 16:07
@lopsided98
Copy link
Contributor

The user creation is not guarded by the mkIf cfg.enable which is causing a cfssl user to be created on every NixOS user's system, as well as the /var/lib/cfssl directory.

@kalbasit
Copy link
Member

@lopsided98 I confirm seen them on my system. Can you open a separate issue so we can track it and fix it in a separate PR? Thx!

@srhb
Copy link
Contributor

srhb commented Aug 21, 2018

On it.

@lopsided98
Copy link
Contributor

I'm writing a PR right now, the fix is pretty simple.

@srhb
Copy link
Contributor

srhb commented Aug 21, 2018

@lopsided98 Oh, okay.

@lopsided98
Copy link
Contributor

See #45441

@infinisil
Copy link
Member

Whoops, totally missed that!

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.

None yet

6 participants