Repository navigation
feat(identity): Create columns for AuthProvider in IdentityProvider - #26930
leedongwei wants to merge 2 commits into
Conversation
|
This PR has a migration; here is the generated SQL BEGIN;
--
-- Create model IdentityProviderSsoConfig
--
CREATE TABLE "sentry_identityproviderssoconfig" ("id" bigserial NOT NULL PRIMARY KEY, "default_team_id" bigint NULL, "default_role" integer NOT NULL CHECK ("default_role" >= 0), "default_global_access" boolean NOT NULL, "flags" bigint NOT NULL);
--
-- Add field last_sync to identityprovider
--
ALTER TABLE "sentry_identityprovider" ADD COLUMN "last_sync" timestamp with time zone NULL;
--
-- Add field identityprovider to identityproviderssoconfig
--
ALTER TABLE "sentry_identityproviderssoconfig" ADD COLUMN "identityprovider_id" bigint NOT NULL;
--
-- Add field organization to identityprovider
--
ALTER TABLE "sentry_identityprovider" ADD COLUMN "organization_id" bigint NULL;
--
-- Add field authprovider to identityprovider
--
ALTER TABLE "sentry_identityprovider" ADD COLUMN "authprovider_id" bigint NULL;
ALTER TABLE "sentry_identityproviderssoconfig" ADD CONSTRAINT "sentry_identityprovi_default_team_id_0fad5285_fk_sentry_te" FOREIGN KEY ("default_team_id") REFERENCES "sentry_team" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "sentry_identityproviderssoconfig_default_team_id_0fad5285" ON "sentry_identityproviderssoconfig" ("default_team_id");
CREATE INDEX "sentry_identityproviderssoconfig_identityprovider_id_4fa9e8a9" ON "sentry_identityproviderssoconfig" ("identityprovider_id");
ALTER TABLE "sentry_identityproviderssoconfig" ADD CONSTRAINT "sentry_identityprovi_identityprovider_id_4fa9e8a9_fk_sentry_id" FOREIGN KEY ("identityprovider_id") REFERENCES "sentry_identityprovider" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "sentry_identityprovider_organization_id_8e46f82d" ON "sentry_identityprovider" ("organization_id");
ALTER TABLE "sentry_identityprovider" ADD CONSTRAINT "sentry_identityprovi_organization_id_8e46f82d_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "sentry_identityprovider_authprovider_id_d28c33c2" ON "sentry_identityprovider" ("authprovider_id");
ALTER TABLE "sentry_identityprovider" ADD CONSTRAINT "sentry_identityprovi_authprovider_id_d28c33c2_fk_sentry_au" FOREIGN KEY ("authprovider_id") REFERENCES "sentry_authprovider" ("id") DEFERRABLE INITIALLY DEFERRED;
COMMIT; |
| external_id = models.CharField(max_length=64, null=True) | ||
|
|
||
| # SSO-specific fields | ||
| is_sso = models.BooleanField(default=False) |
There was a problem hiding this comment.
It's not really safe to add a default like this - The way Django does this is to create the default at the DB level to backfill the column then remove it, and handle the default at the application level. Creating the default at the DB level requires Postgres to lock the table while it rewrites it.
What you can do here is use SeparateDatabaseAndState to have Postgres just create the column without the default, but keep the default in Django so that new rows are created as expected. Then since you'll be backfilling anyway, you can fill in the default values as part of that.
There was a problem hiding this comment.
Updated diff does not have any backfills on this table. Noted for the future.
| "sentry.Team", blank=True, null=True, on_delete=models.SET_NULL | ||
| ) | ||
| sso_default_role = BoundedPositiveIntegerField(default=0) | ||
| sso_default_global_access = models.BooleanField(default=False) |
There was a problem hiding this comment.
All of this is configuration and should just be part of the data. These shouldn't need to be columns because we're not going to be querying on any of this.
There was a problem hiding this comment.
I don't really agree with this. If these are important attributes of the provider it makes sense for them to be fields on the model, rather than a schemaless blob
There was a problem hiding this comment.
The IdentityProvider model is designed to generically represent an external provider. Configuration such as auth tokens and other information about how to use the specific provider is stored in the json field. the types of IDPs are represented as provider classes in the sentry.identity module (which is where the auth provider stuff should end up moving.
I think the configuration that these attributes represent for the SSO type of identity provider does not need to be explicit fields on the model which many identity providers will not even use.
There was a problem hiding this comment.
Tokens etc make sense, especially since it's an encrypted field. I don't know enough about the specifics of these other config values, but if these attributes will be used across multiple providers I think it's better for them to be columns, even if they're null sometimes.
There was a problem hiding this comment.
I think there should be distinct separation between provider-related config and Sentry-related config.
These columns hold SSO defaults, which are relevant to Sentry application only. I've moved into a separate table for now.
The config field on this table is used for storing data coming from the providers and the schema varies based on the provider. IMO mixing both types of config data is a bad idea.
| # To be renamed to "provider" because this is a bad column name | ||
| type = models.CharField(max_length=64) | ||
| # Replacing "type" | ||
| provider = models.CharField(max_length=64, null=True) |
There was a problem hiding this comment.
Do you have an argument for renaming this? I don't think we actually need to rename this? If we are going to rename this, I would prefer to see this done outside of this PR.
Also I actually think this name is fine no? It is the type of identity provider, as described in the doc comment above
The IdentityProvider is unique on the type of provider (eg github, slack, google, etc).
There was a problem hiding this comment.
What's the different between this two sentences?
The IdentityProvider is unique on the type of provider (eg github, slack, google, etc).
vs
The IdentityProvider is unique for each provider (eg github, slack, google, etc).
What does the word "type" mean, or what does it add to the first sentence?
There was a problem hiding this comment.
It adds specificity and avoids stutter. Imagine you did this
identity_provider = IdentityProvider.objects.get(id=1)
# Using provider as the provider identifier, has stutter
print(identity_provider.provider)
# Using type as the provider identifier, no stutter is more clear
print(identity_provider.type)5121389 to
3529347
Compare
3529347 to
9121418
Compare
9121418 to
4bc1a02
Compare
4bc1a02 to
1c3864e
Compare
1c3864e to
0c9a780
Compare
There was a problem hiding this comment.
Might be worth a comment on what 50 is?
There was a problem hiding this comment.
Why do we have this if unused? Just part of the spec?
There was a problem hiding this comment.
Nit: We usually don't use underscores other than sentry_, which I think mimics the table name that Django would have produced. So sentry_identityproviderssoconfig
0c9a780 to
006181b
Compare
|
Not sure why there's still a failure to generate SQL |
| "sentry.Team", blank=True, null=True, on_delete=models.SET_NULL | ||
| ) | ||
|
|
||
| default_role = BoundedPositiveIntegerField(default=50) # Default to member |
There was a problem hiding this comment.
I still don't really understand this - 50 is member in what context? Is this specific to a provider, or in some spec?
There was a problem hiding this comment.
Member for Sentry role. I'll update the comment in a bit.
|
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
This is a series of PR to merge
IdentityProviderandAuthProviderinto 1 model/table.At the moment, they will need to go through COPS to disconnect their Google identities from their Sentry account. This will make it easier for users to manage their external identities from Slack/MS Teams/Okta/Google/etc.
Part 1: IdentityProvider add new columns (#26930) ← Here
Part 2: IdentityProvider dual-write to 2 columns (#26931)
Part 3: AuthProvider dual-write to 2 tables (#26932)