Skip to content

Allow disabling of automatic DomainClaim creation - #10537

Merged
knative-prow-robot merged 6 commits into
knative:masterfrom
julz:cdc-noautocreate
Jan 14, 2021
Merged

knative-prow-robot merged 6 commits into
knative:masterfrom
julz:cdc-noautocreate

Conversation

@julz

@julz julz commented Jan 13, 2021

Copy link
Copy Markdown
Contributor

Part of #9713.

Implements autocreateClusterDomainClaim config. This allows multi-tenant clusters to safely use Domain Mapping, by preventing automatic creation of ClusterDomainClaims in the reconciler. With this option disabled in the config (it defaults to true), domain names must be explicitly delegated to a particular namespace by cluster administrators by creating a ClusterDomainClaim with an appropriate spec.Namespace field. This is important to prevent domain squatting/interception when DNS is being pointed to a shared cluster.

Release Note

Introduces autocreateClusterDomainClaim in config-network config map. This allows DomainMappings to be safely used in shared clusters by disabling automatic ClusterDomainClaim creation. With this option set to "false", cluster administrators must explicitly delegate domain names to namespaces by creating a ClusterDomainClaim with an appropriate spec.Namespace set. 

/assign @mattmoor @tcnghia

@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label Jan 13, 2021
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/API API objects and controllers labels Jan 13, 2021
@codecov

codecov Bot commented Jan 13, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #10537 (4d4b093) into master (d28e461) will increase coverage by 0.00%.
The diff coverage is 87.50%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #10537   +/-   ##
=======================================
  Coverage   88.10%   88.11%           
=======================================
  Files         187      187           
  Lines        8870     8874    +4     
=======================================
+ Hits         7815     7819    +4     
+ Misses        815      813    -2     
- Partials      240      242    +2     
Impacted Files Coverage Δ
pkg/reconciler/domainmapping/reconciler.go 92.53% <87.50%> (-0.27%) ⬇️
pkg/reconciler/autoscaling/kpa/scaler.go 88.57% <0.00%> (-1.43%) ⬇️
pkg/activator/handler/handler.go 94.87% <0.00%> (-0.48%) ⬇️
pkg/reconciler/autoscaling/kpa/kpa.go 94.64% <0.00%> (-0.05%) ⬇️
pkg/activator/util/header.go 100.00% <0.00%> (ø)
cmd/queue/main.go 0.51% <0.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d28e461...4d4b093. Read the comment docs.

@julz

julz commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

/retest


dc, err := r.netclient.NetworkingV1alpha1().ClusterDomainClaims().Create(ctx, resources.MakeDomainClaim(dm), metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("failed to create ClusterDomainClaim: %w", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: one of these error has "domain mapping:" prefix while the other doesn't

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also one says "cluster domain claim" while the other uses "ClusterDomainClaim"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, dropped the prefix since it doesn't look like we use them elsewhere for stuff like this

if dc, err = r.netclient.NetworkingV1alpha1().ClusterDomainClaims().Create(ctx, resources.MakeDomainClaim(dm), metav1.CreateOptions{}); err != nil {
return fmt.Errorf("failed to create ClusterDomainClaim: %w", err)
dc, err = r.createDomainClaimIfAllowed(ctx, dm)
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fold assignment into if?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did it like this to try to make clear as possible that this is updating the outer dc and doesn't shadow it, but I'll happily change if you don't think this made that clearer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, thanks. I don't mind keeping it this way, please feel free to do so.

But I think @vagababov will one day change it anyway 🤣.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😂

@julz

julz commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

/retest

@tcnghia tcnghia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2021
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, tcnghia

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 13, 2021
@julz

julz commented Jan 13, 2021

Copy link
Copy Markdown
Contributor Author

/retest

// FinalizeKind cleans up the ClusterDomainClaim created by the DomainMapping.
func (r *Reconciler) FinalizeKind(ctx context.Context, dm *v1alpha1.DomainMapping) reconciler.Event {
if !config.FromContext(ctx).Network.AutocreateClusterDomainClaims {
// If we're not responsible for creating domain claims, we're not responsible for cleaning them up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what if I created DM and then disabled the flag? Should we still cleanup the existing ones?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think no, if the flag is disabled that implies the administrator is going to manage creating/deleting claims.

return nil
}

func (r *Reconciler) createDomainClaimIfAllowed(ctx context.Context, dm *v1alpha1.DomainMapping) (*netv1alpha1.ClusterDomainClaim, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this name presumes there's a createDC without any allowance check. I think just createDomainClaim is fine, especially that it's an internal method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2021
return fmt.Errorf("failed to get ClusterDomainClaim: %w", err)
}

if dm.Namespace != dc.Spec.Namespace {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd move this as the else clause of IsNotFound, since it's meaningless to check it when we just built the dc above — we know NS would mathch.

@vagababov vagababov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2021
@julz

julz commented Jan 14, 2021

Copy link
Copy Markdown
Contributor Author

/retest

@julz

julz commented Jan 14, 2021

Copy link
Copy Markdown
Contributor Author

Hmm.

/retest

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. 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.

5 participants