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

feat(onboarding,cloud-host-scanner): v2 enables cloud_account GCP WIF usage [SSPROD-35921] #487

Merged
merged 28 commits into from
Mar 8, 2024

Conversation

wideawakening
Copy link
Contributor

@wideawakening wideawakening commented Mar 5, 2024

duplicated from #480, after resolving conflicts on master (to include #482).
had to add a small fix since tests were not passing


@wideawakening wideawakening marked this pull request as ready for review March 6, 2024 11:35
@@ -555,10 +574,12 @@ func componentsToResourceData(components []*cloudauth.AccountComponent) []map[st

// internal type redefintion for GCP service principals.
// This exists because in terraform, the key is originally provided in the form of a base64 encoded json string

// note; caution with order of fields, they have to go in alphabetical ASC so that the json marshalled on the tf read phase produces no drift https://github.com/golang/go/issues/27179
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @cgeers just so you are aware of this.
for me it's ok to merge with this

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still scratching my head on they why here, but I'm willing to accept it as a benign change that spoon feeds our tf tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha, yeah... if you want to dig more into the issue feel free to do so, but let's agree on some criteria to accept this PR and unblock us; you can work on digging more anytime later.

i was there for couple of days and i'm ok letting it go...
gotta say though, i'm not expert on go, neither the json libraries. maybe you do see some other option

}

component.Metadata = metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the functional difference in this change set, starting at L390. If there is one, I don't see it. I think if you look closer, this same behavior was more elegantly expressed previously, with less opportunity for tedium and failure.

This provider should not be in the business of asserting component metadata validity, or otherwise looking for ways to error. The API it talks to does that. This provider code should be as thin and agnostic as it possibly can be, so that future states are compatible out of the box and we don't have to baby sit this code.

Copy link
Contributor Author

@wideawakening wideawakening Mar 7, 2024

Choose a reason for hiding this comment

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

ok, i reverted the whole block.

i see your point after validating that the master branch code passes tests just with the > change.

probably it was due to figuring out the error on the drift (caused by the json marshalling) that i wanted to put the two use-cases separatedly

  • key data is present > we populate key
  • wif data is present (+email as dependency) > we populate wif

but i agree that with the code on the block

component.Metadata = &cloudauth.AccountComponent_ServicePrincipalMetadata{ServicePrincipalMetadata: &cloudauth.ServicePrincipalMetadata{}}
err = protojson.Unmarshal([]byte(value.(string)), component.GetServicePrincipalMetadata())

for our use case, is more than enough.

it is misleading though, that if the key is present the wif data is written, again.

@@ -555,10 +574,12 @@ func componentsToResourceData(components []*cloudauth.AccountComponent) []map[st

// internal type redefintion for GCP service principals.
// This exists because in terraform, the key is originally provided in the form of a base64 encoded json string

// note; caution with order of fields, they have to go in alphabetical ASC so that the json marshalled on the tf read phase produces no drift https://github.com/golang/go/issues/27179
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still scratching my head on they why here, but I'm willing to accept it as a benign change that spoon feeds our tf tests

Copy link
Contributor

@cgeers cgeers left a comment

Choose a reason for hiding this comment

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

I've applied your test cases to main, and they consistently pass with after the Email order change and the >= -> > change in L390. Can we please revert the GCP handling to the former structure?

@@ -387,26 +387,42 @@ func constructAccountComponents(data *schema.ResourceData) []*cloudauth.AccountC
if data.Get(SchemaCloudProviderType).(string) == cloudauth.Provider_PROVIDER_GCP.String() {
spGcp := &internalServicePrincipalMetadata{}
err = json.Unmarshal([]byte(value.(string)), spGcp)
if len(spGcp.Gcp.Key) >= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

>= is a legitimate, but the only bug here. Should be >, which I'd like to see be the only change within this section

@wideawakening wideawakening enabled auto-merge (squash) March 7, 2024 08:17
Copy link
Contributor

@cgeers cgeers left a comment

Choose a reason for hiding this comment

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

Thanks @wideawakening looks good!

@wideawakening wideawakening merged commit 0aae6b7 into master Mar 8, 2024
23 checks passed
@wideawakening wideawakening deleted the gcp-agentless-onboarding-2 branch March 8, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants