Skip to content
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

[ROUTER-890] Ability to skip safelisting enforcement via plugin #6403

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

glasser
Copy link
Member

@glasser glasser commented Dec 5, 2024

If safelisting is enabled, a router_service plugin can skip enforcement of the safelist (including the require_id check) by adding the key apollo_persisted_queries::safelist::skip_enforcement with value true to the request context.

(This does not affect the logging of unknown operations by the persisted_queries.log_unknown option.)

In cases where an operation would have been denied but is allowed due to the context key existing, the attribute
persisted_queries.safelist.enforcement_skipped is set on the apollo.router.operations.persisted_queries metric with value true.

This PR improves the testing of that metric as well.

When writing the tests, I discovered that the
persisted_queries.safelist.rejected.unknown attribute had its value set to false when the operation is denied but not logged, and to true when denied and logged. (You can also tell whether it is logged via the persisted_queries.logged attribute.) This dated to the creation of this metric in #3609 and seems to be a mistake. This PR normalizes this attribute to always be true if it is set. The metric was described as unstable when released in v1.28.1, so this seems reasonable.

@glasser glasser requested review from a team as code owners December 5, 2024 01:59
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Dec 5, 2024

✅ Docs Preview Ready

Configuration
{
  "repoOverrides": {
    "apollographql/router@main": {
      "remote": {
        "owner": "apollographql",
        "repo": "router",
        "branch": "glasser/pq-safelist-override"
      }
    }
  }
}
Name Link

Commit

8b1fe2a

Preview

https://www.apollographql.com/docs/deploy-preview/b0f4e84dbdf840deb24c

Build ID

b0f4e84dbdf840deb24c

File Changes

0 new, 9 changed, 0 removed
* graphos/reference/router/telemetry/instrumentation/standard-attributes.mdx
* graphos/reference/router/telemetry/instrumentation/standard-instruments.mdx
* graphos/reference/router/telemetry/instrumentation/selectors.mdx
* graphos/reference/router/telemetry/metrics-exporters/datadog.mdx
* graphos/reference/router/telemetry/trace-exporters/datadog.mdx
* graphos/reference/router/configuration.mdx
* graphos/routing/observability/client-awareness.mdx
* graphos/routing/security/persisted-queries.mdx
* graphos/routing/configure-your-router.mdx

Pages

9


9 pages published. Build will be available for 30 days.

@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

(PR still needs a small doc update and changeset, but otherwise should be good. Note that this is built on top of #6198.)

@router-perf
Copy link

router-perf bot commented Dec 5, 2024

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

@glasser glasser force-pushed the glasser/pq-client-name branch from bf7ba2c to 8b459b7 Compare December 5, 2024 02:47
@glasser glasser requested a review from a team as a code owner December 5, 2024 02:47
@glasser glasser force-pushed the glasser/pq-safelist-override branch 2 times, most recently from 909ebfb to 4cee254 Compare December 5, 2024 03:39
@glasser glasser mentioned this pull request Dec 5, 2024
6 tasks

let (_mock_guard, uplink_config) = mock_pq_uplink(&manifest).await;
assert_counter!(
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that I wrote and tested all the assert_counter calls on a clean checkout before I rewrote the u64_counter calls to use the attributes vector because I was a bit paranoid that I would do something accidental like change bool true to string "true".

@@ -106,7 +106,7 @@ expression: yaml
- fields:
alg: ES256
reason: "invalid type: string \"Hmm\", expected a sequence"
index: 5
index: 5
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops this is a typo I should revert I think

@@ -130,7 +130,7 @@ Use `with_subscriber` to attach a subscriber to an async block.
```rust
#[tokio::test]
async fn test_async() {
async{...}.with_subscriber(assert_snapshot_subscriber!())
async{...}.with_subscriber(assert_snapshot_subscriber!()).await
Copy link
Member Author

Choose a reason for hiding this comment

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

Despite my need to make minor tweaks I really appreciated both of these dev docs!

@glasser glasser force-pushed the glasser/pq-safelist-override branch from 4cee254 to acafab0 Compare December 5, 2024 21:50
@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

!docs preview main

1 similar comment
@BlenderDude
Copy link
Member

!docs preview main

@glasser glasser force-pushed the glasser/pq-client-name branch from 8b459b7 to 0797d3e Compare December 5, 2024 22:12
@glasser glasser force-pushed the glasser/pq-safelist-override branch from acafab0 to 0655ba2 Compare December 5, 2024 22:13
@glasser glasser force-pushed the glasser/pq-client-name branch from 0797d3e to 2bbe77c Compare December 5, 2024 22:14
@glasser glasser force-pushed the glasser/pq-safelist-override branch from 0655ba2 to abbde21 Compare December 5, 2024 22:14
@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

!docs preview main

@glasser glasser force-pushed the glasser/pq-safelist-override branch from abbde21 to a81aab8 Compare December 5, 2024 22:23
@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

!docs preview main

@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

(btw this !docs preview main thing is a brand-new feature from @BlenderDude which pretty soon won't need to be re-run every time you push)

@glasser glasser force-pushed the glasser/pq-safelist-override branch from a81aab8 to 8a14702 Compare December 5, 2024 22:35
@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

!docs preview main

@glasser glasser requested a review from BrynCooke December 5, 2024 22:38
@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

OK, this one is ready for review as well. Docs and changesets should be done. This merges into #6198.

@glasser glasser force-pushed the glasser/pq-client-name branch from 2bbe77c to 54e79ca Compare December 5, 2024 22:40
If safelisting is enabled, a `router_service` plugin can skip
enforcement of the safelist (including the `require_id` check) by adding
the key `apollo_persisted_queries::safelist::skip_enforcement` with
value `true` to the request context.

(This does not affect the logging of unknown operations by the
`persisted_queries.log_unknown` option.)

In cases where an operation would have been denied but is allowed due to
the context key existing, the attribute
`persisted_queries.safelist.enforcement_skipped` is set on the
`apollo.router.operations.persisted_queries` metric with value true.

This PR improves the testing of that metric as well.

When writing the tests, I discovered that the
`persisted_queries.safelist.rejected.unknown` attribute had its value
set to `false` when the operation is denied but not logged, and to
`true` when denied and logged. (You can also tell whether it is logged
via the `persisted_queries.logged` attribute.) This dated to the
creation of this metric in #3609 and seems to be a mistake. This PR
normalizes this attribute to always be `true` if it is set. The metric
was described as unstable when released in v1.28.1, so this seems
reasonable.
@glasser glasser force-pushed the glasser/pq-safelist-override branch from 8a14702 to 8b1fe2a Compare December 5, 2024 22:41
@glasser
Copy link
Member Author

glasser commented Dec 5, 2024

!docs preview main

true,
));
}
u64_counter!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonderful! One callsite for metrics.

Base automatically changed from glasser/pq-client-name to dev December 6, 2024 16:29
@BrynCooke BrynCooke merged commit b42ead6 into dev Dec 9, 2024
12 checks passed
@BrynCooke BrynCooke deleted the glasser/pq-safelist-override branch December 9, 2024 09:56
@BrynCooke BrynCooke mentioned this pull request Dec 16, 2024
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.

4 participants