Skip to content

Set alpnOverride depending on TLS Mode #44918

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 2 commits into from
Jul 28, 2023
Merged

Conversation

ksubrmnn
Copy link
Contributor

@ksubrmnn ksubrmnn commented May 15, 2023

Please provide a description of this PR:

By setting tls.mode SIMPLE, the user is signaling that they want to opt out of mTLS, Istio managed or otherwise. Since ALPN rewrite exists solely for the purpose of starting Istio mTLS, it violates the user’s intent to perform said rewrite.

This PR checks if the TLS mode is simple and then adds a field to the filter metadata to indicate whether the proxy should proceed with the alpn header rewrite.

Partially fixes #40680

Istio/proxy change: istio/proxy#4783

@istio-testing
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 15, 2023
@istio-policy-bot istio-policy-bot added area/networking release-notes-none Indicates a PR that does not require release notes. labels May 15, 2023
@istio-testing istio-testing added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 15, 2023
@ksubrmnn ksubrmnn force-pushed the alpn branch 2 times, most recently from 4bdbda5 to 6d0c539 Compare May 15, 2023 19:26
@ksubrmnn
Copy link
Contributor Author

/retest

@istio-testing istio-testing added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 15, 2023
@ksubrmnn ksubrmnn changed the title Set alpnOverride Set alpnOverride depending on TLS Mode May 16, 2023
@ksubrmnn ksubrmnn marked this pull request as ready for review May 16, 2023 18:09
@ksubrmnn ksubrmnn requested review from a team as code owners May 16, 2023 18:09
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 16, 2023
@howardjohn
Copy link
Member

was there some istio/proxy change to enable this?

@howardjohn
Copy link
Member

should add the test in #42902

@ksubrmnn
Copy link
Contributor Author

was there some istio/proxy change to enable this?

#42902

Updated PR description to reflect that istio/proxy changes are to follow

@ksubrmnn
Copy link
Contributor Author

#42902

I've included just a unit test for this change to verify that the filtermetada is set correctly. I will follow up with integration testing after the proxy changes.

@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 31, 2023
Copy link
Contributor

@keithmattix keithmattix left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

Overall looks good, a few small comments. Its a bit hard to properly review without the istio/proxy changes though, ideally we merge those first.

@@ -294,6 +294,13 @@ func (cb *ClusterBuilder) applyDestinationRule(mc *MutableCluster, clusterMode C

if destRule != nil {
mc.cluster.Metadata = util.AddConfigInfoMetadata(mc.cluster.Metadata, destRule.Meta)

// ALPN header rewrite starts mTLS. Skip if TLS mode is SIMPLE.
trafficPolicy := destinationRule.GetTrafficPolicy()
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to use opts.policy which is not the same as destinationRule. Actually I would do this inside of applyTrafficPolicy as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what is the difference between destinationRule.GetTrafficPolicy() and opts.policy?

Copy link
Member

Choose a reason for hiding this comment

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

It is the result of MergeTrafficPolicy which does some merging logic

Copy link
Contributor Author

@ksubrmnn ksubrmnn Jul 13, 2023

Choose a reason for hiding this comment

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

for applyTrafficPolicy, would we want to modify the opts.mutable.cluster.Metadata. If so, then we need to modify the return type which could mean making changes wherever it is called in the case that opts is nil

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to modify any return ttpes? Can't we just just set opts.mutable.cluster.metadata = util.AddALPNOverrideToMetadata(mc.cluster.Metadata, alpnOverride)?

@@ -435,6 +435,30 @@ func AddSubsetToMetadata(md *core.Metadata, subset string) {
}
}

// AddALPNOverrideToMetadata adds whether the the ALPN prefix should be added to the header
// to the given core.Metadata struct, if metadata is not initialized, build a new metadata.
func AddALPNOverrideToMetadata(metadata *core.Metadata, alpnOverride bool) *core.Metadata {
Copy link
Member

Choose a reason for hiding this comment

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

can we just only include the metadata if alpnOverride is true (or false, I am not sure which one means "do not set it")?

Its not free to add the metadata, actually surprisingly high cost

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added return metadata if alpnOverride is true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added logic to configureALPNOverride

@howardjohn
Copy link
Member

howardjohn commented Jun 5, 2023 via email

@jewertow
Copy link
Member

jewertow commented Jul 4, 2023

Hey @ksubrmnn, are you going to continue to work on this PR? I am interested in this change and I wonder if it will end up in master.

@ksubrmnn
Copy link
Contributor Author

@jewertow Yes I'm working on this PR. Had some delay with proxy changes, but you can find them at istio/proxy#4783

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Jul 13, 2023
@ksubrmnn ksubrmnn added do-not-merge Block automatic merging of a PR. do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. and removed do-not-merge Block automatic merging of a PR. labels Jul 13, 2023
@ksubrmnn
Copy link
Contributor Author

WIP tests will fail since still working on applyTrafficPolicy part

@@ -1432,3 +1441,14 @@ func (cb *ClusterBuilder) buildExternalSDSCluster(addr string) *cluster.Cluster
}
return c
}

// configureALPNOverride determines whether alpn_override should be added to metadata
func configureALPNOverride(tlsMode networking.ClientTLSSettings_TLSmode, md *core.Metadata) *core.Metadata {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you added a comment somewhere on the issue, but do you even need to return anything here since you're passing a pointer to md? In fact AddALPNOverrideToMetadata probably doesn't need a return value either if you're manipulating a pointer value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you do because if the metadata is nil, we want to return a new metadata with the headers. That's the only reason. Empty metadata can be modified and set, but not nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then why pass a pointer in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it's stored in the mutable cluster.

@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Jul 27, 2023
@ksubrmnn
Copy link
Contributor Author

@howardjohn I've removed the changes to apply traffic policy. The PR was getting to be a bit large and unwieldy for me. I prefer to add those changes in a followup

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>
@ksubrmnn ksubrmnn removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Jul 27, 2023
Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>
Copy link
Contributor

@keithmattix keithmattix left a comment

Choose a reason for hiding this comment

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

Approving since changes are coming in a follow up PR

@istio-testing istio-testing merged commit bd9a7c4 into istio:master Jul 28, 2023
pull bot pushed a commit to sniperking1234/istio that referenced this pull request Jul 28, 2023
* Set alpnOverride

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>

* remove test logs

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>

---------

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>
luksa pushed a commit to luksa/istio that referenced this pull request Apr 11, 2024
…e"` for SIMPLE and MUTUAL TLS (istio#833)

* Set alpnOverride depending on TLS Mode (istio#44918)

* Set alpnOverride

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>

* remove test logs

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>

---------

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>

* pilot: set `istio.alpn_override: false` in subset clusters (istio#46496) (istio#46529)

* Add tests for destination rules with port level settings

* Add test cases for subsets

* Refactor AddALPNOverrideToMetadata

* Update comment for AddALPNOverrideToMetadata

* Fix lint error

* Add release note

* Fix release note

---------

Signed-off-by: Jacek Ewertowski <jewertow@redhat.com>

---------

Signed-off-by: Kalya Subramanian <kasubra@microsoft.com>
Signed-off-by: Jacek Ewertowski <jewertow@redhat.com>
Co-authored-by: Kalya Subramanian <42158129+ksubrmnn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking release-notes-none Indicates a PR that does not require release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ALPN filter incorrectly applies to non-Istio TLS traffic
6 participants