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

cli: add --generate-config flag to constellation iam create command, which creates a config file with IAM values filled in #782

Merged
merged 16 commits into from
Jan 12, 2023

Conversation

msanft
Copy link
Contributor

@msanft msanft commented Dec 12, 2022

Proposed change(s)

  • Add a generate-config flag to the constellation iam create command which enables automatic generation of a config file (path specified by the config flag. By default, constellation-conf.yaml) and automatic filling of the resulting IAM values into said file.

Checklist

@netlify
Copy link

netlify bot commented Dec 12, 2022

Deploy Preview for constellation-docs canceled.

Name Link
🔨 Latest commit 0b12950
🔍 Latest deploy log https://app.netlify.com/sites/constellation-docs/deploys/63bfdc11b4bf7300087d56ee

@msanft
Copy link
Contributor Author

msanft commented Dec 12, 2022

RFC
Currently, config.New() has no option to customize or disable config validation, which would be needed to use it to load an incomplete config (all IAM values & measurements will be missing at the point where i load it). Therefore i made a temporary function config.NewWithoutValidation() which skips the validation step. This is not a clean solution. I think we should allow an option to provide a custom validation function to config.New(). What do you think?

@msanft msanft requested review from 3u13r, datosh and katexochen and removed request for datosh, katexochen and 3u13r December 12, 2022 10:39
@3u13r
Copy link
Member

3u13r commented Dec 13, 2022

Short summary from today's stand-up discussion:

  • We don't want to write the IAM credentials/information directly into the constellation-conf.yaml but we want to reference a file (similar to what GCP already does)
  • This way we you can safely share even Azure constellation-conf.yaml which currently include secrets
  • This should side-step the requested change for moving the validation
  • The field should be provider specific (aka. be .provider.azure.IAMConfig and not .IAMConfig)
  • The new file will probably be one struct for which includes all fields for all CSPs which is then marshalled into the file.

@datosh
Copy link
Contributor

datosh commented Dec 13, 2022

Therefore i made a temporary function config.NewWithoutValidation() which skips the validation step. This is not a clean solution. I think we should allow an option to provide a custom validation function to config.New(). What do you think?

(Maybe it wont be necessary, but) I like the solution. The goal of config.New was to make it hard to use it wrong, e.g., for the to validate the config. NewWithoutValidation is explicit about what it is skipping. I think the API is good 🙂

What do you think is not clean about the solution or should be improved?

You could share more code between New and NewWithoutValidation so maintenance is easier. Maybe have a private new that implement most of the new logic.

@msanft
Copy link
Contributor Author

msanft commented Dec 14, 2022

What do you think is not clean about the solution or should be improved?

I think it might be better to keep the "working (at that point in time)" validation steps (such as checking if all fields are there and if the file is not corrupted generally) could be kept to prevent errors when the values are later on inserted into the file. But with the proposed rework, that would not be necessary i guess ;-)

@msanft
Copy link
Contributor Author

msanft commented Dec 14, 2022

We don't want to write the IAM credentials/information directly into the constellation-conf.yaml but we want to reference a file (similar to what GCP already does)

Since the values created by the iam create step are also used in other steps (e.g. create), we would also have to change all accesses to these values in the rest of the code. Since only 1 value of 1 cloud provider is sensitive here, i think we should rather look for another way. I might be missing a big point here, but from my thinking there are other ways to prevent the secret being exposed in the file.

This way we you can safely share even Azure constellation-conf.yaml which currently include secrets

We could also tackle this by using the environment variable CONSTELL_AZURE_CLIENT_SECRET_VALUE

@msanft
Copy link
Contributor Author

msanft commented Jan 5, 2023

Last consensus was (iirc):

  • Leave constellation iam create as is, do not add config values automatically from there but only print them and ask the user to paste them in the config
  • Create an opt-in for creating iam resources and filling iam values into the config automatically at the constellation config generate command

@katexochen are you OK with that?

@katexochen
Copy link
Member

@katexochen are you OK with that?

Yes, sounds good! :)

@msanft
Copy link
Contributor Author

msanft commented Jan 5, 2023

Any1 got an idea on how to implement this in a "clean" manner?

I think adding all IAM-flags for every CP to config generate would be ugly and redundant as we have them on iam create already. But how could we get around it? Have subcommands for config generate? Seems ugly as well.

Any ideas are welcome 😄

@msanft msanft added this to the v2.4.0 milestone Jan 5, 2023
@msanft msanft added the no changelog Change won't be listed in release changelog label Jan 5, 2023
@msanft msanft self-assigned this Jan 5, 2023
@msanft msanft linked an issue Jan 5, 2023 that may be closed by this pull request
6 tasks
@katexochen
Copy link
Member

Create an opt-in for creating iam resources and filling iam values into the config automatically at the constellation config generate command

Iirc Thomas and I were also okay with adding an opt-in option to iam command to generate config instead, but you didn't like it this way? Would solve the problem imo...

@msanft
Copy link
Contributor Author

msanft commented Jan 5, 2023

Create an opt-in for creating iam resources and filling iam values into the config automatically at the constellation config generate command

Iirc Thomas and I were also okay with adding an opt-in option to iam command to generate config instead, but you didn't like it this way? Would solve the problem imo...

Sounds good. Maybe I mixed something up, I thought you were against doing it that way. Then I'll go work on that! Thank you :)

@katexochen
Copy link
Member

I thought you were against doing it that way

I was just against doing that opt-out.

@katexochen katexochen modified the milestones: v2.4.0, v.2.5.0 Jan 5, 2023
@msanft msanft removed the no changelog Change won't be listed in release changelog label Jan 5, 2023
@msanft msanft removed a link to an issue Jan 5, 2023
6 tasks
@msanft msanft added the feature This introduces new functionality label Jan 9, 2023
@msanft msanft changed the title AB#2706 Automatically add IAM values to config cli: automatically add iam values to config Jan 11, 2023
Copy link
Contributor

@datosh datosh left a comment

Choose a reason for hiding this comment

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

Yes, the chosen approach works for me as well!

I have built & tested the current state locally for Azure. I have two comments, but they are unrelated to this PR (so we can choose to fix this here or in another PR):

The output when creating resources for Azure is misaligned. I think it would be more readable to have a consistent indentation for region, resource group & service principal:

./constellation iam create azure --region westus --resourceGroup fabian-delete-me-iam --servicePrincipal fabian-delete-me-iam --generate-config
The following IAM configuration will be created:
Region: westus
Resource Group: fabian-delete-me-iam
Service Principal:      fabian-delete-me-iam
The configuration file constellation-conf.yaml will be automatically generated and populated with the IAM values.
Do you want to create the configuration? [y/n]: y
Creating  
Your IAM configuration was created and filled into constellation-conf.yaml successfully.

The help text for resource group is not correct:

--resourceGroup string      Name of the resource group your IAM resources will be created in.

When I run iam create two resource groups seem to be created. The one I provided and an additional with suffix -identity. The suffixed one contains the IAM resources mentioned in helptext. I think we should mention both in helptext.

Copy link
Member

@katexochen katexochen left a comment

Choose a reason for hiding this comment

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

Only some minor architecture and language comments, idea looks good so far.

cli/internal/cmd/iamcreateaws.go Outdated Show resolved Hide resolved
cli/internal/cmd/iamcreateaws.go Outdated Show resolved Hide resolved
cli/internal/cmd/iamcreateaws_test.go Outdated Show resolved Hide resolved
cli/internal/cmd/configgenerate.go Outdated Show resolved Hide resolved
cli/internal/cmd/configgenerate.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
@msanft msanft marked this pull request as ready for review January 11, 2023 10:51
@msanft msanft removed the request for review from datosh January 11, 2023 10:51
Copy link
Member

@katexochen katexochen left a comment

Choose a reason for hiding this comment

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

lgtm, well done. 🐳

Some minor follow ups that shouldn't be done in this PR:

  • The IAM commands currently lack debug logging, we should add some lines, at least the parsed flags etc
  • Look if we can reducing redundancy in the IAM commands, maybe by introducing an interface that the the flags fullfill, so that that the core logic doesn't have to be duplicated

@msanft
Copy link
Contributor Author

msanft commented Jan 11, 2023

The IAM commands currently lack debug logging, we should add some lines, at least the parsed flags etc

I forgot to mention this in our conversation today. I only discovered this today, think we had a bad timing between merging IAM and Debug logging so that they "missed" each other.

Look if we can reducing redundancy in the IAM commands, maybe by introducing an interface that the the flags fullfill, so that that the core logic doesn't have to be duplicated

Agreed.

I will bring up both points in the next backlog refinement.

@katexochen
Copy link
Member

I will bring up both points in the next backlog refinement.

Feel free to already create tickets for this and start implementation in a separate PR as you like.

@msanft
Copy link
Contributor Author

msanft commented Jan 12, 2023

@katexochen am I missing something or could we omit the second "if"-clause here? Just noticed it

if flags.file == "-" {
content, err := encoder.NewEncoder(conf).Encode()
if err != nil {
return fmt.Errorf("encoding config content: %w", err)
}
cg.log.Debugf("Writing YAML data to stdout")
_, err = cmd.OutOrStdout().Write(content)
return err
}
cg.log.Debugf("Writing YAML data to configuration file")
if err := fileHandler.WriteYAML(flags.file, conf, file.OptMkdirAll); err != nil {
return err
}
if flags.file != "-" {
cmd.Println("Config file written to", flags.file)
cmd.Println("Please fill in your CSP-specific configuration before proceeding.")
cmd.Println("For more information refer to the documentation:")
cmd.Println("\thttps://docs.edgeless.systems/constellation/getting-started/first-steps")
}

@msanft msanft merged commit 64ec040 into main Jan 12, 2023
@msanft msanft deleted the feat/IAMConfigFilling branch January 12, 2023 10:35
malt3 pushed a commit that referenced this pull request Jan 12, 2023
* AB#2706 Automatically add IAM values to config

(cherry picked from commit 64ec040)
malt3 pushed a commit that referenced this pull request Jan 12, 2023
* AB#2706 Automatically add IAM values to config

(cherry picked from commit 64ec040)
@m1ghtym0 m1ghtym0 mentioned this pull request Jan 17, 2023
8 tasks
@thomasten thomasten changed the title cli: automatically add iam values to config cli: add --generate-config flag to constellation iam create command, which creates a config file with IAM values filled in Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This introduces new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants