Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/externalsecrets/v1beta1/secretsstore_infisical_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ type InfisicalProvider struct {
// +kubebuilder:default="https://app.infisical.com/api"
// +optional
HostAPI string `json:"hostAPI,omitempty"`
// OrganizationSlug is the slug of the organization to authenticate with.
// Required when the machine identity has access to multiple organizations (e.g. sub-organizations).
// +optional
OrganizationSlug string `json:"organizationSlug,omitempty"`
}
7 changes: 4 additions & 3 deletions pkg/provider/infisical/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ func NewAPIClient(baseURL string) (*InfisicalClient, error) {
return api, nil
}

func (a *InfisicalClient) SetTokenViaMachineIdentity(clientID, clientSecret string) error {
func (a *InfisicalClient) SetTokenViaMachineIdentity(clientID, clientSecret, organizationSlug string) error {
if a.token != "" {
return nil
}

loginResponse, err := a.MachineIdentityLoginViaUniversalAuth(MachineIdentityUniversalAuthLoginRequest{
ClientID: clientID,
ClientSecret: clientSecret,
ClientID: clientID,
ClientSecret: clientSecret,
OrganizationSlug: organizationSlug,
})
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions pkg/provider/infisical/api/api_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type MachineIdentityDetailsResponse struct {
}

type MachineIdentityUniversalAuthLoginRequest struct {
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
OrganizationSlug string `json:"organizationSlug,omitempty"`
}

type RevokeMachineIdentityAccessTokenRequest struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/infisical/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (p *Provider) NewClient(ctx context.Context, store esv1beta1.GenericStore,
return nil, err
}

if err := apiClient.SetTokenViaMachineIdentity(clientID, clientSecret); err != nil {
if err := apiClient.SetTokenViaMachineIdentity(clientID, clientSecret, infisicalSpec.OrganizationSlug); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 No test coverage for organizationSlug propagation

The existing provider_test.go injects MockInfisicalClient directly (bypassing SetTokenViaMachineIdentity), so there is no test that exercises the new organizationSlug path through NewClient. If a future refactor accidentally drops the slug from the call, the test suite would not catch it. Consider adding an integration-style test or extending MockInfisicalClient.MachineIdentityLoginViaUniversalAuth to capture and assert the OrganizationSlug field.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

return nil, fmt.Errorf("failed to authenticate via universal auth %w", err)
}

Expand Down