Skip to content

Commit

Permalink
v11 deprecation (#17047)
Browse files Browse the repository at this point in the history
* Complete deprecation for OIDC RedirectURL - #12054.

* Complete deprecation for CreateSessionTracker - #12304.

* Complete deprecation for SSO Auth Request http endpoints - #13073.

* Complete deprecation for #12795.

* Complete deprecation for http GenerateToken - #9024.
  • Loading branch information
Joerger committed Oct 6, 2022
1 parent f828ac7 commit 38f4779
Show file tree
Hide file tree
Showing 12 changed files with 1,652 additions and 2,821 deletions.
27 changes: 0 additions & 27 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,6 @@ func (c *Client) GetOIDCConnector(ctx context.Context, name string, withSecrets
if err != nil {
return nil, trail.FromGRPC(err)
}
// An old server would send RedirectURL instead of RedirectURLs
// DELETE IN 11.0.0
resp.CheckSetRedirectURL()
return resp, nil
}

Expand All @@ -1530,9 +1527,6 @@ func (c *Client) GetOIDCConnectors(ctx context.Context, withSecrets bool) ([]typ
}
oidcConnectors := make([]types.OIDCConnector, len(resp.OIDCConnectors))
for i, oidcConnector := range resp.OIDCConnectors {
// An old server would send RedirectURL instead of RedirectURLs
// DELETE IN 11.0.0
oidcConnector.CheckSetRedirectURL()
oidcConnectors[i] = oidcConnector
}
return oidcConnectors, nil
Expand All @@ -1544,9 +1538,6 @@ func (c *Client) UpsertOIDCConnector(ctx context.Context, oidcConnector types.OI
if !ok {
return trace.BadParameter("invalid type %T", oidcConnector)
}
// An old server would expect RedirectURL instead of RedirectURLs
// DELETE IN 11.0.0
connector.CheckSetRedirectURL()
_, err := c.grpc.UpsertOIDCConnector(ctx, connector, c.callOpts...)
return trail.FromGRPC(err)
}
Expand Down Expand Up @@ -2728,24 +2719,6 @@ func (c *Client) CreateSessionTracker(ctx context.Context, st types.SessionTrack
}

req := &proto.CreateSessionTrackerRequest{SessionTracker: v1}

// DELETE IN 11.0.0
// Early v9 versions use a flattened out types.SessionTrackerV1
req.ID = v1.Spec.SessionID
req.Type = v1.Spec.Kind
req.Reason = v1.Spec.Reason
req.Invited = v1.Spec.Invited
req.Hostname = v1.Spec.Hostname
req.Address = v1.Spec.Address
req.ClusterName = v1.Spec.ClusterName
req.Login = v1.Spec.Login
req.Expires = v1.Spec.Expires
req.KubernetesCluster = v1.Spec.KubernetesCluster
req.HostUser = v1.Spec.HostUser
if len(v1.Spec.Participants) > 0 {
req.Initiator = &v1.Spec.Participants[0]
}

tracker, err := c.grpc.CreateSessionTracker(ctx, req, c.callOpts...)
if err != nil {
return nil, trail.FromGRPC(err)
Expand Down
98 changes: 0 additions & 98 deletions api/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,104 +640,6 @@ func TestGetResources(t *testing.T) {
}
}

type mockOIDCConnectorServer struct {
*mockServer
connectors map[string]*types.OIDCConnectorV3
}

func newMockOIDCConnectorServer() *mockOIDCConnectorServer {
m := &mockOIDCConnectorServer{
&mockServer{
grpc: grpc.NewServer(),
UnimplementedAuthServiceServer: &proto.UnimplementedAuthServiceServer{},
},
make(map[string]*types.OIDCConnectorV3),
}
proto.RegisterAuthServiceServer(m.grpc, m)
return m
}

func startMockOIDCConnectorServer(t *testing.T) string {
l, err := net.Listen("tcp", "")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, l.Close()) })
go newMockOIDCConnectorServer().grpc.Serve(l)
return l.Addr().String()
}

func (m *mockOIDCConnectorServer) GetOIDCConnector(ctx context.Context, req *types.ResourceWithSecretsRequest) (*types.OIDCConnectorV3, error) {
conn, ok := m.connectors[req.Name]
if !ok {
return nil, trace.NotFound("not found")
}
return conn, nil
}

func (m *mockOIDCConnectorServer) GetOIDCConnectors(ctx context.Context, req *types.ResourcesWithSecretsRequest) (*types.OIDCConnectorV3List, error) {
var connectors []*types.OIDCConnectorV3
for _, conn := range m.connectors {
connectors = append(connectors, conn)
}
return &types.OIDCConnectorV3List{
OIDCConnectors: connectors,
}, nil
}

func (m *mockOIDCConnectorServer) UpsertOIDCConnector(ctx context.Context, oidcConnector *types.OIDCConnectorV3) (*emptypb.Empty, error) {
m.connectors[oidcConnector.Metadata.Name] = oidcConnector
return &emptypb.Empty{}, nil
}

// Test that client will perform properly with an old server
// DELETE IN 11.0.0
func TestSetOIDCRedirectURLBackwardsCompatibility(t *testing.T) {
ctx := context.Background()
addr := startMockOIDCConnectorServer(t)

// Create client
clt, err := New(ctx, Config{
Addrs: []string{addr},
Credentials: []Credentials{
&mockInsecureTLSCredentials{}, // TODO(Joerger) replace insecure credentials
},
DialOpts: []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()), // TODO(Joerger) remove insecure dial option
},
})
require.NoError(t, err)

conn := &types.OIDCConnectorV3{
Metadata: types.Metadata{
Name: "one",
},
}

// Upsert should set "RedirectURL" on the provided connector if empty
conn.Spec.RedirectURLs = []string{"one.example.com"}
conn.Spec.RedirectURL = ""
err = clt.UpsertOIDCConnector(ctx, conn)
require.NoError(t, err)
require.Equal(t, 1, len(conn.GetRedirectURLs()))
require.Equal(t, conn.GetRedirectURLs()[0], conn.Spec.RedirectURL)

// GetOIDCConnector should set "RedirectURLs" on the received connector if empty
conn.Spec.RedirectURLs = []string{}
conn.Spec.RedirectURL = "one.example.com"
connResp, err := clt.GetOIDCConnector(ctx, conn.GetName(), false)
require.NoError(t, err)
require.Equal(t, 1, len(connResp.GetRedirectURLs()))
require.Equal(t, connResp.GetRedirectURLs()[0], "one.example.com")

// GetOIDCConnectors should set "RedirectURLs" on the received connectors if empty
conn.Spec.RedirectURLs = []string{}
conn.Spec.RedirectURL = "one.example.com"
connectorsResp, err := clt.GetOIDCConnectors(ctx, false)
require.NoError(t, err)
require.Equal(t, 1, len(connectorsResp))
require.Equal(t, 1, len(connectorsResp[0].GetRedirectURLs()))
require.Equal(t, "one.example.com", connectorsResp[0].GetRedirectURLs()[0])
}

type mockAccessRequestServer struct {
*mockServer
}
Expand Down
Loading

0 comments on commit 38f4779

Please sign in to comment.