Skip to content

Refactor app access#19387

Merged
GavinFrazar merged 10 commits intomasterfrom
gavinfrazar/refactor-app-access-middleware
Dec 23, 2022
Merged

Refactor app access#19387
GavinFrazar merged 10 commits intomasterfrom
gavinfrazar/refactor-app-access-middleware

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

@GavinFrazar GavinFrazar commented Dec 15, 2022

This PR refactors app access to move the logic in the AWS handler and Azure handler out of RoundTrip and into ServeHTTP, since we were not following the RoundTripper interface requirements in multiple ways. Also, oxy.Forwarder documents that middleware should be done using ServeHTTP not in RoundTrip.

This PR also moves the AWS signing service into lib/utils/aws/signing.go so that it can be re-used for database-access DynamoDB in a future PR.

I tested that app access including AWS and Azure still work.

* Move logic out of RoundTrip and into ServeHTTP as a middleware before handing off to oxy forwarder
* Move AWS signing service code into lib/utils/aws/signing.go
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

@Tener requesting your review since this PR affects the Azure integration you just added. As mentioned above I tested that Azure integration still works with an Azure VM, managed identity, and tsh az ....

@GavinFrazar GavinFrazar force-pushed the gavinfrazar/refactor-app-access-middleware branch from 71d0419 to 4f81b26 Compare December 15, 2022 22:50
Copy link
Copy Markdown
Contributor

@jakule jakule left a comment

Choose a reason for hiding this comment

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

PR looks fine. Accepting with a few comments.

Comment thread lib/utils/aws/signing.go
Comment thread lib/srv/app/aws/handler_test.go Outdated
Comment thread lib/srv/app/aws/handler.go Outdated
Comment thread lib/srv/app/common/audit.go Outdated
Comment thread lib/srv/app/common/audit.go Outdated
Comment thread lib/srv/app/aws/handler.go Outdated
Comment thread lib/utils/aws/signing.go Outdated
* check auditErr instead of err for logging
* use app server close context for audit event emitting
* add go doc comments.
* refactor request rewriting to make the copy in a more robust way.
* pass status code as uint32 rather than casting in audit emitter
* clone request in signing service
@GavinFrazar GavinFrazar requested a review from tigrato December 17, 2022 01:49
The handlers for aws/azure were inside of an oxy/forward.Forwarder
RoundTrip function but once moved outside of that we should not pass
host header of the inbound request.

* Set oxy forwarder to PassHostHeader=false to ensure the host header is
  the URL being sought.
* Remove code that deleted forwarding headers previously, we should keep
  those (X-Forwarded-*).
* Audit log the AWS Host sought rather than the incoming request Host
  header (prior behavior maintained, we just rewrite the request
  differently using Clone).
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

GavinFrazar commented Dec 22, 2022

want to give @Tener a chance to take a look when he's back before I merge this

@github-actions github-actions Bot removed the request for review from Tener December 22, 2022 01:03
Copy link
Copy Markdown
Contributor

@Tener Tener left a comment

Choose a reason for hiding this comment

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

Thank you for this refactor, much appreciated.

@GavinFrazar GavinFrazar disabled auto-merge December 22, 2022 19:02
@GavinFrazar GavinFrazar enabled auto-merge (squash) December 22, 2022 19:06
@GavinFrazar GavinFrazar merged commit eccfd93 into master Dec 23, 2022
@github-actions
Copy link
Copy Markdown
Contributor

@GavinFrazar See the table below for backport results.

Branch Result
branch/v11 Failed

@GavinFrazar GavinFrazar deleted the gavinfrazar/refactor-app-access-middleware branch December 23, 2022 18:05
GavinFrazar added a commit that referenced this pull request Dec 24, 2022
* Move logic out of RoundTrip and into ServeHTTP as a middleware before handing off to oxy forwarder
* Move AWS signing service code into lib/utils/aws/signing.go
* use app server close context for audit event emitting
* add go doc comments.
* refactor request rewriting to make the copy in a more robust way.
* pass status code as uint32 rather than casting in audit emitter
* clone request instead of making a new request, and rewrite url to force https
* update header handling
* Set oxy forwarder to PassHostHeader=false to ensure the host header is
  the URL being sought.
* Remove code that deleted forwarding headers previously, we should keep
  those (X-Forwarded-*).
* Audit log the AWS Host sought rather than the incoming request Host
  header (prior behavior maintained, we just rewrite the request
  differently using Clone).
* Remove obsolete header copying helper func
GavinFrazar added a commit that referenced this pull request Dec 29, 2022
* Move logic out of RoundTrip and into ServeHTTP as a middleware before handing off to oxy forwarder
* Move AWS signing service code into lib/utils/aws/signing.go
* use app server close context for audit event emitting
* add go doc comments.
* refactor request rewriting to make the copy in a more robust way.
* pass status code as uint32 rather than casting in audit emitter
* clone request instead of making a new request, and rewrite url to force https
* update header handling
* Set oxy forwarder to PassHostHeader=false to ensure the host header is
  the URL being sought.
* Remove code that deleted forwarding headers previously, we should keep
  those (X-Forwarded-*).
* Audit log the AWS Host sought rather than the incoming request Host
  header (prior behavior maintained, we just rewrite the request
  differently using Clone).
* Remove obsolete header copying helper func
GavinFrazar added a commit that referenced this pull request Dec 29, 2022
* Emit new event for DynamoDB requests via app access (#17595)

* Add a new event for app access requests sent to AWS DynamoDB

* Refactor app access (#19387)

* Move logic out of RoundTrip and into ServeHTTP as a middleware before handing off to oxy forwarder
* Move AWS signing service code into lib/utils/aws/signing.go
* use app server close context for audit event emitting
* add go doc comments.
* refactor request rewriting to make the copy in a more robust way.
* pass status code as uint32 rather than casting in audit emitter
* clone request instead of making a new request, and rewrite url to force https
* update header handling
* Set oxy forwarder to PassHostHeader=false to ensure the host header is
  the URL being sought.
* Remove code that deleted forwarding headers previously, we should keep
  those (X-Forwarded-*).
* Audit log the AWS Host sought rather than the incoming request Host
  header (prior behavior maintained, we just rewrite the request
  differently using Clone).
* Remove obsolete header copying helper func

* Remove api error header from backport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants