Skip to content

Commit

Permalink
add saml wizard to ui (#27518)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudream committed Jun 16, 2023
1 parent 1b69fbc commit 6be5d88
Show file tree
Hide file tree
Showing 32 changed files with 2,332 additions and 1,987 deletions.
370 changes: 187 additions & 183 deletions api/gen/proto/go/usageevents/v1/usageevents.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/proto/teleport/usageevents/v1/usageevents.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ enum DiscoverResource {
DISCOVER_RESOURCE_DOC_DATABASE_RDS_PROXY = 34;
DISCOVER_RESOURCE_DOC_DATABASE_HIGH_AVAILABILITY = 35;
DISCOVER_RESOURCE_DOC_DATABASE_DYNAMIC_REGISTRATION = 36;

DISCOVER_RESOURCE_SAML_APPLICATION = 37;
}

// DiscoverResourceMetadata contains common metadata identifying resource type being added.
Expand Down
176 changes: 91 additions & 85 deletions gen/proto/go/prehog/v1alpha/teleport.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gen/proto/js/prehog/v1alpha/teleport_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gen/proto/js/prehog/v1alpha/teleport_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions lib/services/saml_idp_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,21 @@ func UnmarshalSAMLIdPServiceProvider(data []byte, opts ...MarshalOption) (types.
}
return nil, trace.BadParameter("unsupported SAML IdP service provider resource version %q", h.Version)
}

// GenerateIdPServiceProviderFromFields takes `name` and `entityDescriptor` fields and returns a SAMLIdPServiceProvider.
func GenerateIdPServiceProviderFromFields(name string, entityDescriptor string) (types.SAMLIdPServiceProvider, error) {
if len(name) == 0 {
return nil, trace.BadParameter("missing name")
}
if len(entityDescriptor) == 0 {
return nil, trace.BadParameter("missing entity descriptor")
}

var s types.SAMLIdPServiceProviderV1
s.SetName(name)
s.SetEntityDescriptor(entityDescriptor)
if err := s.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
return &s, nil
}
4 changes: 4 additions & 0 deletions lib/web/ui/usercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type userACL struct {
Locks access `json:"lock"`
// Assist defines access to assist feature.
Assist access `json:"assist"`
// SAMLIdpServiceProvider defines access to `saml_idp_service_provider` objects.
SAMLIdpServiceProvider access `json:"samlIdpServiceProvider"`
}

type authType string
Expand Down Expand Up @@ -197,6 +199,7 @@ func NewUserContext(user types.User, userRoles services.RoleSet, features proto.
requestAccess := newAccess(userRoles, ctx, types.KindAccessRequest)
desktopAccess := newAccess(userRoles, ctx, types.KindWindowsDesktop)
cnDiagnosticAccess := newAccess(userRoles, ctx, types.KindConnectionDiagnostic)
samlIdpServiceProviderAccess := newAccess(userRoles, ctx, types.KindSAMLIdPServiceProvider)

var assistAccess access
if features.Assist {
Expand Down Expand Up @@ -251,6 +254,7 @@ func NewUserContext(user types.User, userRoles services.RoleSet, features proto.
DeviceTrust: deviceTrust,
Locks: lockAccess,
Assist: assistAccess,
SAMLIdpServiceProvider: samlIdpServiceProviderAccess,
}

// local user
Expand Down
2 changes: 2 additions & 0 deletions proto/prehog/v1alpha/teleport.proto
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ enum DiscoverResource {
DISCOVER_RESOURCE_DOC_DATABASE_RDS_PROXY = 34;
DISCOVER_RESOURCE_DOC_DATABASE_HIGH_AVAILABILITY = 35;
DISCOVER_RESOURCE_DOC_DATABASE_DYNAMIC_REGISTRATION = 36;

DISCOVER_RESOURCE_SAML_APPLICATION = 37;
}

// DiscoverResourceMetadata contains common metadata identifying resource type being added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ describe('registering new databases, mainly error checking', () => {
engine: DatabaseEngine.AuroraMysql,
},
} as any,
exitFlow: () => null,
viewConfig: null,
indexedViews: [],
setResourceSpec: () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('test EnrollRdsDatabase.tsx', () => {
},
} as any,
viewConfig: null,
exitFlow: null,
indexedViews: [],
setResourceSpec: () => null,
updateAgentMeta: jest.fn(x => x),
Expand Down
15 changes: 12 additions & 3 deletions web/packages/teleport/src/Discover/Discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { Box } from 'design';
import { FeatureBox } from 'teleport/components/Layout';

import { Navigation } from 'teleport/Discover/Navigation/Navigation';
import { SelectResource } from 'teleport/Discover/SelectResource/SelectResource';
import { SelectResource } from 'teleport/Discover/SelectResource';
import cfg from 'teleport/config';

import { EViewConfigs } from './types';
import { findViewAtIndex } from './flow';

import { DiscoverProvider, useDiscover } from './useDiscover';
Expand Down Expand Up @@ -86,10 +87,18 @@ function DiscoverContent() {
);
}

export function Discover() {
export function DiscoverComponent({ eViewConfigs = [] }: Props) {
return (
<DiscoverProvider>
<DiscoverProvider eViewConfigs={eViewConfigs}>
<DiscoverContent />
</DiscoverProvider>
);
}

export function Discover() {
return <DiscoverComponent />;
}

type Props = {
eViewConfigs?: EViewConfigs;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import { Text, Box } from 'design';

import { ResourceKind } from '../Shared';

import { ResourceSpec } from './types';

export function PermissionsErrorMessage({
resourceKind,
resource,
}: PermissionsErrorMessageProps) {
let action = 'add new';
let productName = '';

switch (resourceKind) {
switch (resource.kind) {
case ResourceKind.Application:
action = `${action} Applications`;
productName = 'Access Application';
Expand All @@ -51,8 +53,8 @@ export function PermissionsErrorMessage({

break;
default:
action = 'unimplemented';
productName = 'unimplemented';
action = `${action} ${resource.name}s`;
productName = `adding ${resource.name}s`;
}

return (
Expand All @@ -75,5 +77,5 @@ export function PermissionsErrorMessage({
}

interface PermissionsErrorMessageProps {
resourceKind: ResourceKind;
resource: ResourceSpec;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
* Copyright 2023 Gravitational, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ResourceKind } from '../Shared';

import { sortResources } from './SelectResource';
import { ResourceSpec } from './types';

test('sortResources sorts resources alphabetically with guided resources first', () => {
const sorted = sortResources(mockUnsorted);

expect(sorted).toMatchObject(mockSorted);
});

const mockUnsorted: ResourceSpec[] = [
{
name: 'jenkins',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
{
name: 'grafana',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
{
name: 'linux',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
{
name: 'apple',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
// Guided
{
name: 'zapier',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
},
{
name: 'amazon',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
},
{
name: 'costco',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
},
];

const mockSorted: ResourceSpec[] = [
{
name: 'amazon',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
},
{
name: 'costco',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
},
{
name: 'zapier',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
},
{
name: 'apple',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
{
name: 'grafana',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
{
name: 'jenkins',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
{
name: 'linux',
kind: ResourceKind.Application,
icon: 'Apple',
event: null,
keywords: 'test',
hasAccess: true,
unguidedLink: 'test.com',
},
];

0 comments on commit 6be5d88

Please sign in to comment.