-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Fetch service account OIDC data #402
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,9 @@ import ( | |
| ) | ||
|
|
||
| type OIDCIdentityQuery struct { | ||
| Skip int `uri:"skip,omitempty" url:"skip,omitempty"` | ||
| Take int `uri:"take,omitempty" url:"take,omitempty"` | ||
| ServiceAccountId string `uri:"serviceAccountId" url:"serviceAccountId"` | ||
| Skip int `uri:"skip" url:"skip"` | ||
| Take int `uri:"take" url:"take"` | ||
| } | ||
|
|
||
| type OIDCIdentity struct { | ||
|
|
@@ -22,6 +23,13 @@ type OIDCIdentity struct { | |
| resources.Resource | ||
| } | ||
|
|
||
| type ServiceAccountOIDCIdentitiesResponse struct { | ||
| ServerUrl string `json:"ServerUrl"` | ||
| ExternalId string `json:"ExternalId"` | ||
| OidcIdentities []*OIDCIdentity `json:"OidcIdentities"` | ||
| Count int `json:"Count"` | ||
| } | ||
|
|
||
| // NewOIDCIdentity initializes a Service Account with required fields. | ||
| func NewOIDCIdentity(serviceAccountID string, name string, issuer string, subject string) *OIDCIdentity { | ||
| return &OIDCIdentity{ | ||
|
|
@@ -77,6 +85,30 @@ func GetOIDCIdentities(client newclient.Client, query OIDCIdentityQuery) (*resou | |
| return res, nil | ||
| } | ||
|
|
||
| // GetServiceAccountOIDCData queries the service account and identities for the provided service account ID | ||
| func GetServiceAccountOIDCData(client newclient.Client, query OIDCIdentityQuery) (*ServiceAccountOIDCIdentitiesResponse, error) { | ||
| if internal.IsEmpty(query.ServiceAccountId) { | ||
| return nil, internal.CreateInvalidParameterError("GetServiceAccountOIDCData", "query.ServiceAccountId") | ||
| } | ||
|
|
||
| values, _ := uritemplates.Struct2map(query) | ||
| if values == nil { | ||
| values = map[string]any{} | ||
| } | ||
|
|
||
| path, err := client.URITemplateCache().Expand(serviceAccountOIDCIDQueryTemplate, values) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| res, err := newclient.Get[ServiceAccountOIDCIdentitiesResponse](client.HttpSession(), path) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return res, nil | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing you've tested these with terraform. But is there a reason its difficult to have tests in go as well? Is it because of the difficulty of creating a service account for it? Is a service account the account you have with an auth application? so you'd need to simmulate an account with an external application?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've tested manually, both using the client directly and via terraform. There are no existing tests for OIDC identities to work from and the setup looks fairly complex |
||
| // GetOIDCIdentityByID queries OIDC identities by ID for the provided service account ID | ||
| func GetOIDCIdentityByID(client newclient.Client, serviceAccountID string, ID string) (*OIDCIdentity, error) { | ||
| path, err := client.URITemplateCache().Expand(serviceAccountOIDC, map[string]any{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would adding this field break old usages of the query if they were wotking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there were working usages of this query, adding ServiceAccountId would not break them since it would default to empty string, but this query was only used for the
GetOIDCIdentitiesfunction which was callingapi/serviceaccounts//oidcidentities/v1{?skip,take}when the service account ID was not provided (note the double forward slash) and that endpoint does not exist on Octopus server.The correct endpoint is
api/serviceaccounts/{serviceAccountId}/oidcidentities/v1{?skip,take}where service account ID, Skip and Take are all requiredUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if someone had used the query to build a custom request so that they could bypass the broken function, there could be a working use of this and I guess we can't exactly predict whether the changes could break custom code. I still think this is a worthwhile change, but could release it as a potentially breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah makes sense. Seems like the custom code situation would be super edge case