Skip to content

[GPCAPIM-310] Add user ID and user role ID headers in proxy#157

Merged
davidhamill1-nhs merged 7 commits intomainfrom
feature/GPCAPIM-310-add-user-details-to-request-in-proxy
Apr 8, 2026
Merged

[GPCAPIM-310] Add user ID and user role ID headers in proxy#157
davidhamill1-nhs merged 7 commits intomainfrom
feature/GPCAPIM-310-add-user-details-to-request-in-proxy

Conversation

@davidhamill1-nhs
Copy link
Copy Markdown
Contributor

@davidhamill1-nhs davidhamill1-nhs commented Apr 7, 2026

Description

Upon receiving a request in the proxy, Apigee, add the user details, user ID and user role ID, to the request before passing it on to the backend.

Context

In order to correctly audit requests, Gateway API and the JWT sent to the provider, requires accurate and safe identifiers for the logged-in users. Proxygen/API Platform allow for this through User ID and User Role ID headers added within the proxy layer, taken from the auth flow within the platform.

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming
  • Exceptions/Exclusions to coding standards (e.g. #noqa or #NOSONAR) are included within this Pull Request.

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@davidhamill1-nhs davidhamill1-nhs requested a review from a team as a code owner April 7, 2026 13:12
Copilot AI review requested due to automatic review settings April 7, 2026 13:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the API proxy configuration to propagate CIS2 identity information, and also refactors gateway-api error/request logging.

Changes:

  • Add target-identity entries for cis2-uuid and cis2-urid in the proxygen APIM template.
  • Remove AbstractCDGError.log() (print-based traceback logging) and centralize error logging in the Flask app.
  • Add request-received logging and structured error logging via app.logger in gateway_api/app.py.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
proxygen/x-nhsd-apim.template.yaml Configures proxy target identity forwarding for CIS2 UUID and URID.
gateway-api/src/gateway_api/common/error.py Removes print/traceback-based logging method from the base error type.
gateway-api/src/gateway_api/app.py Introduces Flask logger usage and logs requests/errors around the structured record endpoint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +36
def log_request_received(request: Request) -> None:
log_details = {
"description": "Received request",
"method": request.method,
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The PR title is focused on adding CIS2 user/user-role identity headers in the proxy config, but this change set also introduces request/error logging behavior changes in gateway_api/app.py. Please either update the PR description to explain the additional scope and rationale, or split the logging refactor into a separate PR to keep changes reviewable and traceable.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@Vox-Ben Vox-Ben left a comment

Choose a reason for hiding this comment

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

  • If I understand this right, we're currently accepting the User ID and Role ID parameters but not actually doing anything with them? Is that what we wanted?
  • What's the logging for? If it's just there for debug is it better to take it out again for now until we've worked out what we're doing with creating a logging system properly?
  • If we're not doing that because it's needed, should it have unit tests?

@davidhamill1-nhs
Copy link
Copy Markdown
Contributor Author

If I understand this right, we're currently accepting the User ID and Role ID parameters but not actually doing anything with them? Is that what we wanted?

Correct. GPCAPIM-309 GPCAPIM-311 pick this header up.

What's the logging for? If it's just there for debug is it better to take it out again for now until we've worked out what we're doing with creating a logging system properly?

Debugging. But given how lightweight it is, and there will definitely be work coming to redo the logging, I'm happy to leave it there.

If we're not doing that because it's needed, should it have unit tests?

For the logging? Given it is not needed, but helpful for development debugging, and there is no conditional logic or functionality. I'm inclined not to write unit tests for it.

@Vox-Ben
Copy link
Copy Markdown
Contributor

Vox-Ben commented Apr 8, 2026

If I understand this right, we're currently accepting the User ID and Role ID parameters but not actually doing anything with them? Is that what we wanted?

Correct. GPCAPIM-309 GPCAPIM-311 pick this header up.

What's the logging for? If it's just there for debug is it better to take it out again for now until we've worked out what we're doing with creating a logging system properly?

Debugging. But given how lightweight it is, and there will definitely be work coming to redo the logging, I'm happy to leave it there.

If we're not doing that because it's needed, should it have unit tests?

For the logging? Given it is not needed, but helpful for development debugging, and there is no conditional logic or functionality. I'm inclined not to write unit tests for it.

👍

Copy link
Copy Markdown
Contributor

@Vox-Ben Vox-Ben left a comment

Choose a reason for hiding this comment

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

LGTM. :-)

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Deployment Complete

@davidhamill1-nhs davidhamill1-nhs merged commit 9a8e175 into main Apr 8, 2026
53 checks passed
@davidhamill1-nhs davidhamill1-nhs deleted the feature/GPCAPIM-310-add-user-details-to-request-in-proxy branch April 8, 2026 14:39
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