-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add certificates settings in settings sti table * Add new /api/public_keys route to get uploaded keys * Add release task to initialize saml * Add saml runtime options * Update variable name * Rename certs settings to add SSO prefix to make it obvious * Add tests to the new certificates code * Add saml release task tests
- Loading branch information
Showing
13 changed files
with
384 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,9 +177,12 @@ if config_env() in [:prod, :demo] do | |
|
||
enable_oidc = System.get_env("ENABLE_OIDC", "false") == "true" | ||
enable_oauth2 = System.get_env("ENABLE_OAUTH2", "false") == "true" | ||
enable_saml = System.get_env("ENABLE_SAML", "false") == "true" | ||
|
||
if enable_oauth2 and enable_oidc do | ||
raise("Cannot start Trento with OIDC and OAUTH2 integrations both enabled.") | ||
if Enum.count([enable_oidc, enable_oauth2, enable_saml], fn enabled -> enabled end) > 1 do | ||
raise( | ||
"Cannot start Trento with multiple SSO options enabled. Use one among: OIDC, OAUTH2 and SAML." | ||
) | ||
end | ||
|
||
config :trento, :oidc, | ||
|
@@ -247,4 +250,57 @@ if config_env() in [:prod, :demo] do | |
] | ||
] | ||
end | ||
|
||
if enable_saml do | ||
saml_dir = System.get_env("SAML_SP_DIR", "/etc/trento/trento-web/saml") | ||
|
||
config :trento, :saml, | ||
enabled: true, | ||
callback_url: "/auth/saml_callback", | ||
idp_id: | ||
System.get_env("SAML_IDP_ID") || | ||
raise("environment variable SAML_IDP_ID is missing") | ||
|
||
config :trento, :pow_assent, | ||
providers: [ | ||
saml_local: [ | ||
strategy: TrentoWeb.Auth.AssentSamlStrategy | ||
] | ||
] | ||
|
||
config :samly, Samly.Provider, | ||
idp_id_from: :path_segment, | ||
service_providers: [ | ||
%{ | ||
id: | ||
System.get_env("SAML_SP_ID") || | ||
raise("environment variable SAML_SP_ID is missing"), | ||
entity_id: System.get_env("SAML_SP_ENTITY_ID", ""), | ||
certfile: Path.join([saml_dir, "cert", "saml.pem"]), | ||
keyfile: Path.join([saml_dir, "cert", "saml_key.pem"]), | ||
contact_name: System.get_env("SAML_SP_CONTACT_NAME", "Trento SP Admin"), | ||
contact_email: System.get_env("SAML_SP_CONTACT_EMAIL", "[email protected]"), | ||
org_name: System.get_env("SAML_SP_ORG_NAME", "Trento SP"), | ||
org_displayname: System.get_env("SAML_SP_ORG_DISPLAYNAME", "SAML SP build with Trento"), | ||
org_url: System.get_env("SAML_SP_ORG_URL", "https://www.trento-project.io/") | ||
} | ||
], | ||
identity_providers: [ | ||
%{ | ||
id: System.get_env("SAML_IDP_ID"), | ||
sp_id: System.get_env("SAML_SP_ID"), | ||
base_url: "https://#{System.get_env("TRENTO_WEB_ORIGIN")}/sso", | ||
metadata_file: Path.join([saml_dir, "metadata.xml"]), | ||
sign_requests: System.get_env("SAML_SIGN_REQUESTS", "true") == "true", | ||
sign_metadata: System.get_env("SAML_SIGN_METADATA", "true") == "true", | ||
signed_assertion_in_resp: System.get_env("SAML_SIGNED_ASSERTION", "true") == "true", | ||
signed_envelopes_in_resp: System.get_env("SAML_SIGNED_ENVELOPES", "true") == "true", | ||
nameid_format: | ||
System.get_env( | ||
"SAML_IDP_NAMEID_FORMAT", | ||
"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" | ||
) | ||
} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Trento.Settings.SSOCertificatesSettings do | ||
@moduledoc """ | ||
SSOCertificatesSettings is the STI projection containing SSL certificates | ||
""" | ||
|
||
use Ecto.Schema | ||
use Trento.Support.Ecto.STI, sti_identifier: :sso_certificates_settings | ||
|
||
import Ecto.Changeset | ||
|
||
alias Trento.Support.Ecto.EncryptedBinary | ||
|
||
@type t :: %__MODULE__{} | ||
|
||
@derive {Jason.Encoder, except: [:__meta__, :__struct__]} | ||
@primary_key {:id, :binary_id, autogenerate: true} | ||
schema "settings" do | ||
field :name, :string, source: :sso_certificates_settings_name | ||
field :key_file, EncryptedBinary, source: :sso_certificates_settings_key_file | ||
field :certificate_file, EncryptedBinary, source: :sso_certificates_settings_certificate_file | ||
|
||
timestamps(type: :utc_datetime_usec) | ||
sti_fields() | ||
end | ||
|
||
@spec changeset(t() | Ecto.Changeset.t(), map) :: Ecto.Changeset.t() | ||
def changeset(certificates_settings, attrs) do | ||
certificates_settings | ||
|> cast(attrs, __MODULE__.__schema__(:fields)) | ||
|> validate_required([:name, :key_file, :certificate_file]) | ||
# TODO: move suse_manager_settings.ex certificates function to some support module | ||
# |> validate_cert_and_key | ||
|> sti_changes() | ||
|> unique_constraint(:type) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
priv/repo/migrations/20240918151940_add_sso_certificates_settings_sti.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Trento.Repo.Migrations.AddSSOCertificatesSettingsSti do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:settings) do | ||
add :sso_certificates_settings_name, :string | ||
add :sso_certificates_settings_key_file, :binary | ||
add :sso_certificates_settings_certificate_file, :binary | ||
end | ||
|
||
create unique_index(:settings, [:sso_certificates_settings_name]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.