Skip to content

Commit 4bdf326

Browse files
feat(guard): extend saml integration with jit provisiooning field (#78)
## Description We are working on a feature to support SAML JIT Provisioning. In order to parallelize further work, I've created this PR to perform necessary DB Migrations. ## Type of Change <!-- Mark relevant items with an [x] --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation/Repository docs update - [ ] Performance improvement - [ ] Code refactoring - [ ] Test updates ## Testing <!-- How has this been tested? --> - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [x] Not applicable ## Documentation <!-- Mark relevant items with an [x] --> - [ ] Documentation update required - [ ] Changelog update required ## Related Issues <!-- Link related issues below. Insert the issue link or issue number --> - Related to: renderedtext/tasks#7566
1 parent d3f4f10 commit 4bdf326

22 files changed

+294
-321
lines changed

ee/rbac/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ home_dir/*
2828
.elixir_ls/
2929
test_report/*
3030
.devcontainer
31+
.tool-versions
3132
docker-compose.local.yml

ee/rbac/lib/rbac/api/project.ex

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ defmodule Rbac.Api.Project do
33

44
def fetch(project_id) do
55
Watchman.benchmark("fetch_project.duration", fn ->
6-
req =
7-
%InternalApi.Projecthub.DescribeRequest{
8-
id: project_id,
9-
metadata: %InternalApi.Projecthub.RequestMeta{}
10-
}
6+
req = %InternalApi.Projecthub.DescribeRequest{
7+
id: project_id,
8+
metadata: %InternalApi.Projecthub.RequestMeta{}
9+
}
1110

12-
{:ok, channel} =
13-
GRPC.Stub.connect(Application.fetch_env!(:rbac, :projecthub_grpc_endpoint))
11+
{:ok, channel} = GRPC.Stub.connect(Application.fetch_env!(:rbac, :projecthub_grpc_endpoint))
1412

1513
result = InternalApi.Projecthub.ProjectService.Stub.describe(channel, req, timeout: 30_000)
1614

ee/rbac/lib/rbac/api/repository.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ defmodule Rbac.Api.Repository do
2020
end
2121

2222
defp fetch_collaborators_request(repository_id, page_token) do
23-
req =
24-
%InternalApi.Repository.ListCollaboratorsRequest{
25-
repository_id: repository_id,
26-
page_token: page_token
27-
}
23+
req = %InternalApi.Repository.ListCollaboratorsRequest{
24+
repository_id: repository_id,
25+
page_token: page_token
26+
}
2827

2928
{:ok, channel} =
3029
GRPC.Stub.connect(Application.fetch_env!(:rbac, :repositoryhub_grpc_endpoint))

ee/rbac/lib/rbac/events/authorization.ex

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ defmodule Rbac.Events.Authorization do
1414
with :ok <- validate(routing_key) do
1515
date_time = DateTime.utc_now()
1616

17-
event =
18-
%InternalApi.Guard.AuthorizationEvent{
19-
org_id: org_id,
20-
project_id: project_id,
21-
user_id: user_id,
22-
timestamp: %Google.Protobuf.Timestamp{
23-
seconds: date_time |> seconds(),
24-
nanos: date_time |> nanos()
25-
}
17+
event = %InternalApi.Guard.AuthorizationEvent{
18+
org_id: org_id,
19+
project_id: project_id,
20+
user_id: user_id,
21+
timestamp: %Google.Protobuf.Timestamp{
22+
seconds: date_time |> seconds(),
23+
nanos: date_time |> nanos()
2624
}
25+
}
2726

2827
message = InternalApi.Guard.AuthorizationEvent.encode(event)
2928

ee/rbac/lib/rbac/events/user_created.ex

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
defmodule Rbac.Events.UserCreated do
22
@spec publish(String.t(), boolean) :: :ok
33
def publish(user_id, invited) do
4-
event =
5-
%InternalApi.User.UserCreated{
6-
user_id: user_id,
7-
invited: invited,
8-
timestamp: %Google.Protobuf.Timestamp{
9-
seconds: DateTime.utc_now() |> DateTime.to_unix(:second)
10-
}
4+
event = %InternalApi.User.UserCreated{
5+
user_id: user_id,
6+
invited: invited,
7+
timestamp: %Google.Protobuf.Timestamp{
8+
seconds: DateTime.utc_now() |> DateTime.to_unix(:second)
119
}
10+
}
1211

1312
message = InternalApi.User.UserCreated.encode(event)
1413

ee/rbac/lib/rbac/events/user_joined_organization.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ defmodule Rbac.Events.UserJoinedOrganization do
1212
end
1313

1414
def publish(user_id, org_id, join_time \\ DateTime.utc_now()) do
15-
event =
16-
%InternalApi.User.UserJoinedOrganization{
17-
user_id: user_id,
18-
org_id: org_id,
19-
timestamp: %Google.Protobuf.Timestamp{seconds: join_time |> DateTime.to_unix(:second)}
20-
}
15+
event = %InternalApi.User.UserJoinedOrganization{
16+
user_id: user_id,
17+
org_id: org_id,
18+
timestamp: %Google.Protobuf.Timestamp{seconds: join_time |> DateTime.to_unix(:second)}
19+
}
2120

2221
message = InternalApi.User.UserJoinedOrganization.encode(event)
2322

ee/rbac/lib/rbac/events/user_left_organization.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
defmodule Rbac.Events.UserLeftOrganization do
22
def publish(user_id, org_id, join_time \\ DateTime.utc_now()) do
3-
event =
4-
%InternalApi.User.UserLeftOrganization{
5-
user_id: user_id,
6-
org_id: org_id,
7-
timestamp: %Google.Protobuf.Timestamp{seconds: join_time |> DateTime.to_unix(:second)}
8-
}
3+
event = %InternalApi.User.UserLeftOrganization{
4+
user_id: user_id,
5+
org_id: org_id,
6+
timestamp: %Google.Protobuf.Timestamp{seconds: join_time |> DateTime.to_unix(:second)}
7+
}
98

109
message = InternalApi.User.UserLeftOrganization.encode(event)
1110

ee/rbac/lib/rbac/events/user_updated.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ defmodule Rbac.Events.UserUpdated do
33

44
@spec publish(String.t(), String.t(), String.t()) :: :ok
55
def publish(user_id, exchange_name, routing_key \\ @routing_key) do
6-
event =
7-
%InternalApi.User.UserUpdated{
8-
user_id: user_id,
9-
timestamp: %Google.Protobuf.Timestamp{
10-
seconds: DateTime.utc_now() |> DateTime.to_unix(:second)
11-
}
6+
event = %InternalApi.User.UserUpdated{
7+
user_id: user_id,
8+
timestamp: %Google.Protobuf.Timestamp{
9+
seconds: DateTime.utc_now() |> DateTime.to_unix(:second)
1210
}
11+
}
1312

1413
message = InternalApi.User.UserUpdated.encode(event)
1514
{:ok, channel} = AMQP.Application.get_channel(:user)

ee/rbac/lib/rbac/okta/integrations.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ defmodule Rbac.Okta.Integration do
1616
org_id,
1717
creator_id,
1818
sso_url,
19-
issuer,
19+
saml_issuer,
2020
certificate,
2121
idempotency_token \\ Ecto.UUID.generate()
2222
) do
2323
with {:ok, fingerprint} <- Certificate.fingerprint(certificate),
2424
{:ok, integration} <-
2525
Rbac.Repo.OktaIntegration.insert_or_update(
26-
org_id,
27-
creator_id,
28-
sso_url,
29-
issuer,
30-
fingerprint,
31-
idempotency_token
26+
org_id: org_id,
27+
creator_id: creator_id,
28+
sso_url: sso_url,
29+
saml_issuer: saml_issuer,
30+
saml_certificate_fingerprint: Base.encode64(fingerprint),
31+
idempotency_token: idempotency_token
3232
) do
3333
{:ok, integration}
3434
else

ee/rbac/lib/rbac/repo/okta_integrations.ex

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ defmodule Rbac.Repo.OktaIntegration do
2626
field(:sso_url, :string)
2727
field(:saml_certificate_fingerprint, :string)
2828
field(:scim_token_hash, :string)
29+
field(:jit_provisioning_enabled, :boolean, default: false)
2930

3031
timestamps()
3132
end
@@ -44,20 +45,14 @@ defmodule Rbac.Repo.OktaIntegration do
4445
)
4546
end
4647

47-
def insert_or_update(org_id, creator_id, sso_url, issuer, fingerprint, idempotency_token) do
48-
integration = %__MODULE__{
49-
org_id: org_id,
50-
creator_id: creator_id,
51-
sso_url: sso_url,
52-
saml_issuer: issuer,
53-
saml_certificate_fingerprint: Base.encode64(fingerprint),
54-
idempotency_token: idempotency_token,
55-
scim_token_hash: ""
56-
}
48+
def insert_or_update(fields \\ []) do
49+
# Each time you want to make any change to the integration, token will be reset
50+
fields = Keyword.put(fields, :scim_token_hash, "")
51+
integration = struct(__MODULE__, fields)
5752

5853
changeset = Rbac.Repo.OktaIntegration.changeset(integration)
5954

60-
case find_idempotent_record(org_id, idempotency_token) do
55+
case find_idempotent_record(fields[:org_id], fields[:idempotency_token]) do
6156
{:ok, integration} ->
6257
{:ok, integration}
6358

0 commit comments

Comments
 (0)