-
-
Notifications
You must be signed in to change notification settings - Fork 54
Auto-scoped tokens #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Auto-scoped tokens #990
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2b3962d
feat(api): add perm_create_domain / perm_delete_domain
peterthomassen 6a310b5
feat(webapp): expose perm_create_domain / perm_delete_domain
peterthomassen a103c92
feat(): use sequential output when building dev images
peterthomassen f825e44
refactor(api): code style
peterthomassen 8b5c822
feat(api): add Token.auto_policy (including default policy logic)
peterthomassen e39fe08
chore(deps): update django requirement from ~=5.1.2 to ~=5.1.3 in /api
dependabot[bot] 490efa8
chore(deps): update django-pgtrigger requirement in /api
dependabot[bot] 0bdf05d
chore(deps): update coverage requirement from ~=7.6.4 to ~=7.6.8 in /api
dependabot[bot] 1ade9d0
feat(api): honor auto_policy during domain creation, closes #885
peterthomassen a7d2cc7
chore(api): comment typo
peterthomassen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
api/desecapi/migrations/0039_token_perm_create_domain_token_perm_delete_domain.py
This file contains hidden or 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 @@ | ||
# Generated by Django 5.1.2 on 2024-11-01 14:29 | ||
|
||
import django.db.migrations.operations.special | ||
from django.db import migrations, models | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
Token = apps.get_model("desecapi", "Token") | ||
db_alias = schema_editor.connection.alias | ||
Token.objects.using(db_alias).filter(tokendomainpolicy__isnull=True).update( | ||
perm_create_domain=True, perm_delete_domain=True | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("desecapi", "0038_user_throttle_daily_rate"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="token", | ||
name="perm_create_domain", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name="token", | ||
name="perm_delete_domain", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.RunPython( | ||
code=forwards_func, | ||
reverse_code=django.db.migrations.operations.special.RunPython.noop, | ||
), | ||
] |
50 changes: 50 additions & 0 deletions
50
api/desecapi/migrations/0040_token_auto_policy_token_token_auto_policy_and_more.py
This file contains hidden or 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,50 @@ | ||
# Generated by Django 5.1.3 on 2024-11-21 15:45 | ||
|
||
import pgtrigger.compiler | ||
import pgtrigger.migrations | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("desecapi", "0039_token_perm_create_domain_token_perm_delete_domain"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="token", | ||
name="auto_policy", | ||
field=models.BooleanField(default=False), | ||
), | ||
pgtrigger.migrations.AddTrigger( | ||
model_name="token", | ||
trigger=pgtrigger.compiler.Trigger( | ||
name="token_auto_policy", | ||
sql=pgtrigger.compiler.UpsertTriggerSql( | ||
constraint="CONSTRAINT", | ||
func="\n IF\n NEW.auto_policy = true AND NOT EXISTS(\n SELECT * FROM desecapi_tokendomainpolicy WHERE token_id = NEW.id AND domain_id IS NULL AND subname IS NULL AND type IS NULL\n )\n THEN\n RAISE EXCEPTION 'Token auto policy without a default policy is not allowed. (token.id=%s)', NEW.id;\n END IF;\n RETURN NULL;\n ", | ||
hash="f2cc6e70892817e04cbfbbff63bd4ddbe05b9aa5", | ||
operation="UPDATE OR INSERT", | ||
pgid="pgtrigger_token_auto_policy_8e6d9", | ||
table="desecapi_token", | ||
timing="DEFERRABLE INITIALLY DEFERRED", | ||
when="AFTER", | ||
), | ||
), | ||
), | ||
pgtrigger.migrations.AddTrigger( | ||
model_name="tokendomainpolicy", | ||
trigger=pgtrigger.compiler.Trigger( | ||
name="default_policy_when_auto_policy", | ||
sql=pgtrigger.compiler.UpsertTriggerSql( | ||
func="\n IF\n OLD.domain_id IS NULL AND OLD.subname IS NULL AND OLD.type IS NULL AND (SELECT auto_policy FROM desecapi_token WHERE id = OLD.token_id) = true\n THEN\n RAISE EXCEPTION 'Cannot delete default policy while auto_policy is in effect. (tokendomainpolicy.id=%s)', OLD.id;\n END IF;\n RETURN OLD;\n ", | ||
hash="3d55e73e6ae7d089b5ff136ac16f0c2675285bf2", | ||
operation="DELETE", | ||
pgid="pgtrigger_default_policy_when_auto_policy_a1fd2", | ||
table="desecapi_tokendomainpolicy", | ||
when="BEFORE", | ||
), | ||
), | ||
), | ||
] |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.