Skip to content

Store ASN with IP addresses ; add ability to restrict based on ASN#25030

Open
diox wants to merge 6 commits into
mozilla:masterfrom
diox:store-asn
Open

Store ASN with IP addresses ; add ability to restrict based on ASN#25030
diox wants to merge 6 commits into
mozilla:masterfrom
diox:store-asn

Conversation

@diox

@diox diox commented Jun 15, 2026

Copy link
Copy Markdown
Member

Fixes https://mozilla-hub.atlassian.net/browse/AMOENG-2549
Fixes https://mozilla-hub.atlassian.net/browse/AMOENG-2550

Description

This adds ASN data to IPLog whenever we store ip addresses (provided by Fastly through the Asn header).

This also adds a way to restrict requests and/or auto-approval from their ASN, similar to what we already have for email or IP addresses, as well as admin tools to manipulate that data.

Context

Like IP addresses and other metadata, we have to store that on the FileUpload inside request_metadata at upload, to then override whatever the current thread has when we create the final Version, in case that version is created in a task.

This then allows not only IPLog to be created with the correct value, but also the restriction stuff to use that metadata for auto-approval restrictions.

Testing

Locally, you'll have to uncomment the addons.conf.template bit to pass an hardcoded Asn header to your requests and restart nginx. From there:

  • Submitting an add-on through any mean (API, devhub) should record the Asn in IPLog together with your IP address.
    • Same with any other activity defined with store_ip = True on the activity constant class
  • If there is a restriction for that ASN in the admin (users > Asn user restrictions) it should affect submission or auto-approval depending on what is set

uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Protocol ssl;
# Asn 64496–64511 are reserved for testing etc
# uwsgi_param HTTP_Asn 64496;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with JA4 this can be uncommented to test locally.

@diox diox marked this pull request as ready for review June 15, 2026 14:17
@diox diox requested review from a team and eviljeff and removed request for a team June 15, 2026 14:17

@eviljeff eviljeff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(going to test, just submitting my comments in the meantime)

'details',
'kept_forever',
'ip_address',
'asn',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does iplog__asn work here? (I'm going to keep asking until we can actually make use of that new feature 😆)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried! Unfortunately I had to revert that, because it turns out such lookups are not allowed in fields or readonly_fields, only list_display. It raises a system check error if you try.

Documentation for fields says:

The fields option accepts the same types of values as list_display, except that callables and __ lookups for related fields aren’t accepted.

# must take care of overriding remote addr if the action is created
# from a task.
# must take care of overriding remote addr/metadata if the action
# is created from a task.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we gone through everywhere an existing task might need to do this?

I'm aware it's existing functionality, but it feels fragile to put the onus on each task, when the code that actually saves the activity log may be a few methods abstracted from that task. (I don't have an immediate suggestion how to address this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants