Skip to content

Commit 88ee4c0

Browse files
prevent new aws oidc integrations with invalid DNS labels
1 parent 8685654 commit 88ee4c0

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

lib/auth/integration/integrationv1/service.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/jonboulle/clockwork"
2929
"golang.org/x/crypto/ssh"
3030
"google.golang.org/protobuf/types/known/emptypb"
31+
"k8s.io/apimachinery/pkg/util/validation"
3132

3233
"github.com/gravitational/teleport"
3334
integrationpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/integration/v1"
@@ -230,6 +231,14 @@ func (s *Service) CreateIntegration(ctx context.Context, req *integrationpb.Crea
230231
if err := s.createGitHubCredentials(ctx, req.Integration); err != nil {
231232
return nil, trace.Wrap(err)
232233
}
234+
case types.IntegrationSubKindAWSOIDC:
235+
// AWS OIDC Integration can be used as source of credentials to access AWS Web/CLI.
236+
// This creates a new AppServer whose endpoint is <integrationName>.<proxyURL>, which can fail if integrationName is not a valid DNS Label.
237+
// Instead of failing when the integration is already created, it fails at creation time.
238+
if len(validation.IsDNS1035Label(req.GetIntegration().GetName())) > 0 {
239+
fmt.Println("\n\n LIB AUTH INTEGRATION, invalid integration name", req.GetIntegration().GetName())
240+
return nil, trace.BadParameter("integration name %q must be a valid DNS subdomain so that it can be used to allow Web/CLI access", req.GetIntegration().GetName())
241+
}
233242
}
234243

235244
ig, err := s.backend.CreateIntegration(ctx, req.Integration)

lib/auth/integration/integrationv1/service_test.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package integrationv1
2020

2121
import (
22+
"cmp"
2223
"context"
2324
"testing"
2425

@@ -68,13 +69,14 @@ func TestIntegrationCRUD(t *testing.T) {
6869
}
6970

7071
tt := []struct {
71-
Name string
72-
Role types.RoleSpecV6
73-
Setup func(t *testing.T, igName string)
74-
Test func(ctx context.Context, resourceSvc *Service, igName string) error
75-
Validate func(t *testing.T, igName string)
76-
Cleanup func(t *testing.T, igName string)
77-
ErrAssertion func(error) bool
72+
Name string
73+
Role types.RoleSpecV6
74+
IntegrationName string
75+
Setup func(t *testing.T, igName string)
76+
Test func(ctx context.Context, resourceSvc *Service, igName string) error
77+
Validate func(t *testing.T, igName string)
78+
Cleanup func(t *testing.T, igName string)
79+
ErrAssertion func(error) bool
7880
}{
7981
// Read
8082
{
@@ -186,13 +188,30 @@ func TestIntegrationCRUD(t *testing.T) {
186188
Verbs: []string{types.VerbCreate},
187189
}}},
188190
},
191+
IntegrationName: "integration-allow-create-access",
189192
Test: func(ctx context.Context, resourceSvc *Service, igName string) error {
190193
ig := sampleIntegrationFn(t, igName)
191194
_, err := resourceSvc.CreateIntegration(ctx, &integrationpb.CreateIntegrationRequest{Integration: ig.(*types.IntegrationV1)})
192195
return err
193196
},
194197
ErrAssertion: noError,
195198
},
199+
{
200+
Name: "access to create integrations but name is invalid",
201+
Role: types.RoleSpecV6{
202+
Allow: types.RoleConditions{Rules: []types.Rule{{
203+
Resources: []string{types.KindIntegration},
204+
Verbs: []string{types.VerbCreate},
205+
}}},
206+
},
207+
IntegrationName: "integration-awsoidc-invalid.name",
208+
Test: func(ctx context.Context, resourceSvc *Service, igName string) error {
209+
ig := sampleIntegrationFn(t, igName)
210+
_, err := resourceSvc.CreateIntegration(ctx, &integrationpb.CreateIntegrationRequest{Integration: ig.(*types.IntegrationV1)})
211+
return err
212+
},
213+
ErrAssertion: trace.IsBadParameter,
214+
},
196215
{
197216
Name: "create github integrations",
198217
Role: types.RoleSpecV6{
@@ -496,7 +515,7 @@ func TestIntegrationCRUD(t *testing.T) {
496515
tc := tc
497516
t.Run(tc.Name, func(t *testing.T) {
498517
localCtx := authorizerForDummyUser(t, ctx, tc.Role, localClient)
499-
igName := uuid.NewString()
518+
igName := cmp.Or(tc.IntegrationName, uuid.NewString())
500519
if tc.Setup != nil {
501520
tc.Setup(t, igName)
502521
}

0 commit comments

Comments
 (0)