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

Add enableAdmin and enableACME to Helm values.yml generation #1075

Merged
merged 22 commits into from
Oct 25, 2022

Conversation

hslatman
Copy link
Member

@hslatman hslatman commented Sep 29, 2022

This PR is an attempt at making it possible to process the enableAdmin and enableACME options, so that the generated Helm values.yml for step-ca includes the properties corresponding to these options.

It's an attempt, because it turns out to be more complicated for the enableAdmin option. The option is set to true when --remote-management is provided to ca init. When remote management is enabled, provisioners are stored in the database. But when we're writing the Helm configuration, we can't add provisioners to the DB (which does happen for the non-Helm case), because at that time we don't have a database to write to. This results in the default provisioner not being stored in the database.

@maraino, @dopey what do you think about this? I don't think an Init Container solves this, at least not without also adding some additional logic for handling this. I think we could use some kind of auto migration process that reads the provisioners from ca.json, stores them in the database and deletes them from ca.json. The problem with that is that specifically in this case the ca.json is intended to be read-only, complicating this. One other way I thought of is adding the initial provisioners not through the ca.json, but through another parameter. It would conceptually be fairly close to an Init Container, I guess. Noticed there's a postInitHook that could be of use, maybe?

@github-actions github-actions bot added the needs triage Waiting for discussion / prioritization by team label Sep 29, 2022
@hslatman hslatman changed the title Add enableAdmin and enableACME Add enableAdmin and enableACME to Helm values.yml generation Sep 29, 2022
@maraino
Copy link
Contributor

maraino commented Sep 29, 2022

Right now we have the step provisioner, but an initContainer-like functionality looks like a better idea.

if len(provs) == 0 && !strings.EqualFold(a.config.AuthorityConfig.DeploymentType, "linked") {
// Create First Provisioner
prov, err := CreateFirstProvisioner(ctx, a.adminDB, string(a.password))
if err != nil {
return admin.WrapErrorISE(err, "error creating first provisioner")
}
// Create first admin
if err := a.adminDB.CreateAdmin(ctx, &linkedca.Admin{
ProvisionerId: prov.Id,
Subject: "step",
Type: linkedca.Admin_SUPER_ADMIN,
}); err != nil {
return admin.WrapErrorISE(err, "error creating first admin")
}
}
}

Provisioners stored in the CA configuration file are
automatically migrated to the database.

Currently no cleanup of the provisioners in the
configuration file yet. In certain situations this
may not work as expected, for example if the CA can't
write to the file. But it's probalby good to try it, so
that we can keep the configuration state of the CA consistent.
authority/authority.go Fixed Show resolved Hide resolved
@hslatman
Copy link
Member Author

hslatman commented Oct 6, 2022

At CA startup, a bit of additional logging was added:

badger 2022/10/06 16:58:51 INFO: All 0 tables opened in 0s
2022/10/06 16:58:53 Starting migration of provisioners
2022/10/06 16:58:53 Migrated JWK provisioner "jwk@example.com" with admin permissions
2022/10/06 16:58:53 Migrated ACME provisioner "acme"
2022/10/06 16:58:53 Finished migrating provisioners
2022/10/06 16:58:53 Created super admin "step" for JWK provisioner "jwk@example.com"
2022/10/06 16:58:53 Starting Smallstep CA/0000000-dev (darwin/arm64)
2022/10/06 16:58:53 Documentation: https://u.step.sm/docs/ca
...

I'll see if I can make it respect the --quiet flag too.

@hslatman
Copy link
Member Author

Linting issue seems to be because of smallstep/workflows@825ed94. Unfortunately doesn't show in which files the errors exist: https://github.com/smallstep/certificates/actions/runs/3226727287/jobs/5280607978.

@dopey
Copy link
Contributor

dopey commented Oct 11, 2022

@herman I'll take a look at those

@hslatman
Copy link
Member Author

hslatman commented Oct 12, 2022

@dopey your change worked; no huge number of file exists errors anymore 🙂

Still would need your changes from #1104, but that will probably soon be in.

I really like that handle! Too bad it's not mine 😅

@hslatman hslatman marked this pull request as ready for review October 14, 2022 13:00
@hslatman hslatman force-pushed the herman/remote-management-helm branch from e1ca385 to 9045192 Compare October 14, 2022 14:02
The first super admin subject can now be provided through the
`--admin-subject` flag when initializing a CA.

It's not yet possible to configure the subject of the first
super admin when provisioners are migrated from `ca.json` to the
database. This effectively limits usage of the flag to scenarios
in which the provisioners are written to the database immediately,
so when `--remote-management` is enabled. It currently also doesn't
work with Helm deployments, because there's no mechanism yet to
pass this type of option to the Helm chart.

This commit partially addresses smallstep/cli#697
@hslatman hslatman force-pushed the herman/remote-management-helm branch from 9045192 to d981b9e Compare October 14, 2022 14:04
@hslatman hslatman requested a review from dopey October 14, 2022 14:14
@hslatman
Copy link
Member Author

hslatman commented Oct 14, 2022

In 5700116 I changed the Helm template output to include a default SSHPOP provisioner. This wasn't happening before, probably due to how some config and initialization is intertwined. I assume having it create this provisioner is the right behavior for the Helm case too.

There are a couple of things that I think can be improved when creating a configuration and initializing a CA to make it more maintainable and easier to reason about. I've left some notes and TODOs to remind myself. The tests for the Helm template should help with that, but we need more for the general PKI initialization.

skipInit bool

// If true, does not output initialization logs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If true, does not output initialization logs
// If true, do not output initialization logs

To match the comments above.

Copy link
Contributor

@maraino maraino left a comment

Choose a reason for hiding this comment

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

In my opinion, we shouldn't rewrite the configuration.

pki/pki.go Outdated Show resolved Hide resolved
pki/pki.go Outdated Show resolved Hide resolved
pki/pki.go Outdated Show resolved Hide resolved
pki/pki.go Outdated Show resolved Hide resolved
authority/authority.go Outdated Show resolved Hide resolved
@hslatman hslatman requested a review from maraino October 24, 2022 13:31
@hslatman
Copy link
Member Author

@maraino I've adopted your suggestions and added logging of the token configuration at startup.

Copy link
Contributor

@maraino maraino left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Waiting for discussion / prioritization by team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants