From 96684cc4963f1dd8bf7e98aff5f451c5e039f7a7 Mon Sep 17 00:00:00 2001 From: mjacks258 Date: Wed, 4 Dec 2019 15:41:12 -0700 Subject: [PATCH 1/6] EDNS0 Client Subnet enable on DS level --- docs/source/admin/traffic_router.rst | 5 +- docs/source/api/cdns_name_snapshot.rst | 8 + docs/source/api/cdns_name_snapshot_new.rst | 8 + docs/source/api/deliveryservices.rst | 19 ++- docs/source/api/deliveryservices_id.rst | 12 +- docs/source/api/deliveryservices_id_safe.rst | 7 +- .../api/servers_id_deliveryservices.rst | 7 +- docs/source/api/users_id_deliveryservices.rst | 7 +- docs/source/overview/delivery_services.rst | 6 + lib/go-tc/crconfig.go | 1 + lib/go-tc/deliveryservices.go | 1 + .../20191215000000_add_ecs_enabled.sql | 22 +++ .../crconfig/deliveryservice.go | 4 + .../deliveryservice/deliveryservices.go | 16 +- .../form.deliveryService.DNS.tpl.html | 19 +++ .../form.deliveryService.HTTP.tpl.html | 19 +++ .../form.deliveryService.Steering.tpl.html | 19 +++ .../core/config/ConfigHandler.java | 1 + .../traffic_router/core/dns/NameServer.java | 55 +++++-- .../core/ds/DeliveryService.java | 10 ++ .../core/dns/NameServerTest.java | 151 +++++++++++++++++- 21 files changed, 367 insertions(+), 30 deletions(-) create mode 100644 traffic_ops/app/db/migrations/20191215000000_add_ecs_enabled.sql diff --git a/docs/source/admin/traffic_router.rst b/docs/source/admin/traffic_router.rst index ce307f51a6..1c1e197686 100644 --- a/docs/source/admin/traffic_router.rst +++ b/docs/source/admin/traffic_router.rst @@ -195,7 +195,8 @@ Much of a Traffic Router's configuration can be obtained through the :term:`Para +-----------------------------------------+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+ | CoverageZoneJsonURL | CRConfig.xml | The location (URL) where a :term:`Coverage Zone Map` may be found. | +-----------------------------------------+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+ - | ecsEnable | CRConfig.json | Boolean value to enable or disable ENDS0 client subnet extensions. | + | ecsEnable | CRConfig.json | Boolean value to enable or disable EDNS0 client subnet extensions. | + | | | This is a universal value for the CDN but can be set on the :term:`Delivery Service` level through the :ref:`ds-ecs` field. | +-----------------------------------------+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+ | geolocation.polling.url | CRConfig.json | The location (URL) where a geographic IP mapping database may be found. | +-----------------------------------------+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------+ @@ -539,7 +540,7 @@ DNS Specifics +=======+=================================================================================+===================================================================================================+ | xn | The ID from the client DNS request header | a whole number between 0 and 65535 (inclusive) | +-------+---------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+ - | rhi | The IP address of the resolver when ENDS0 client subnet extensions are enabled. | An IPv4 or IPv6 string, or dash if request is for resolver only and no client subnet is present | + | rhi | The IP address of the resolver when EDNS0 client subnet extensions are enabled. | An IPv4 or IPv6 string, or dash if request is for resolver only and no client subnet is present | +-------+---------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------+ | fqdn | The qname field from the client DNS request message (i.e. the | A series of DNS labels/domains separated by '.' characters and ending with a '.' character | | | :abbr:`FQDN (Fully Qualified Domain Name)` the client is requesting be | | diff --git a/docs/source/api/cdns_name_snapshot.rst b/docs/source/api/cdns_name_snapshot.rst index 7281f0fcb1..847b0f9a56 100644 --- a/docs/source/api/cdns_name_snapshot.rst +++ b/docs/source/api/cdns_name_snapshot.rst @@ -191,6 +191,13 @@ Response Structure :term:`Cache servers` will be chosen at random :domains: An array of domains served by this :term:`Delivery Service` + :ecsEnabled: A string containing a boolean from :ref:`ds-ecs` that tells whether EDNS0 client subnet is enabled on this :term:`Delivery Service`; one of: + + "false" + EDNS0 client subnet is not enabled on this :term:`Delivery Service` + "true" + EDNS0 client subnet is enabled on this :term:`Delivery Service` + :geolocationProvider: The name of a provider for IP-to-geographic-location mapping services - currently the only valid value is ``"maxmindGeolocationService"`` :ip6RoutingEnabled: A string containing a boolean that defines the :ref:`ds-ipv6-routing` setting for this :term:`Delivery Service`; one of: @@ -483,6 +490,7 @@ Response Structure "SOA": "86400" }, "ip6RoutingEnabled": "true", + "ecsEnabled": "false", "routingName": "video", "deepCachingType": "NEVER" } diff --git a/docs/source/api/cdns_name_snapshot_new.rst b/docs/source/api/cdns_name_snapshot_new.rst index 25ee2ae58c..f3a211abbd 100644 --- a/docs/source/api/cdns_name_snapshot_new.rst +++ b/docs/source/api/cdns_name_snapshot_new.rst @@ -190,6 +190,13 @@ Response Structure :term:`Cache servers` will be chosen at random :domains: An array of domains served by this :term:`Delivery Service` + :ecsEnabled: A string containing a boolean from :ref:`ds-ecs` that tells whether EDNS0 client subnet is enabled on this :term:`Delivery Service`; one of: + + "false" + EDNS0 client subnet is not enabled on this :term:`Delivery Service` + "true" + EDNS0 client subnet is enabled on this :term:`Delivery Service` + :geolocationProvider: The name of a provider for IP-to-geographic-location mapping services - currently the only valid value is ``"maxmindGeolocationService"`` :ip6RoutingEnabled: A string containing a boolean that defines the :ref:`ds-ipv6-routing` setting for this :term:`Delivery Service`; one of: @@ -483,6 +490,7 @@ Response Structure "SOA": "86400" }, "ip6RoutingEnabled": "true", + "ecsEnabled": "false", "routingName": "video", "deepCachingType": "NEVER" } diff --git a/docs/source/api/deliveryservices.rst b/docs/source/api/deliveryservices.rst index 33bccbbc05..cb0ff61ae0 100644 --- a/docs/source/api/deliveryservices.rst +++ b/docs/source/api/deliveryservices.rst @@ -90,6 +90,10 @@ Response Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :exampleURLs: An array of :ref:`ds-example-urls` :fqPacingRate: The :ref:`ds-fqpr` @@ -253,7 +257,8 @@ Response Structure "xxx", "zyx" ], - "maxOriginConnections": 0 + "maxOriginConnections": 0, + "ecsEnabled": false }]} @@ -295,6 +300,10 @@ Request Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :fqPacingRate: The :ref:`ds-fqpr` @@ -372,6 +381,7 @@ Request Structure "deepCachingType": "NEVER", "displayName": "test", "dscp": 0, + "ecsEnabled": true, "geoLimit": 0, "geoProvider": 0, "initialDispersion": 1, @@ -427,6 +437,10 @@ Response Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :exampleURLs: An array of :ref:`ds-example-urls` :fqPacingRate: The :ref:`ds-fqpr` @@ -586,7 +600,8 @@ Response Structure ], "deepCachingType": "NEVER", "signingAlgorithm": null, - "tenant": "root" + "tenant": "root", + "ecsEnabled": true } ]} diff --git a/docs/source/api/deliveryservices_id.rst b/docs/source/api/deliveryservices_id.rst index 5d0dcdf27b..4d467ef17c 100644 --- a/docs/source/api/deliveryservices_id.rst +++ b/docs/source/api/deliveryservices_id.rst @@ -100,6 +100,10 @@ Response Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :exampleURLs: An array of :ref:`ds-example-urls` :fqPacingRate: The :ref:`ds-fqpr` @@ -263,7 +267,8 @@ Response Structure "xxx", "zyx" ], - "maxOriginConnections": 0 + "maxOriginConnections": 0, + "ecsEnabled": false }]} @@ -305,6 +310,10 @@ Request Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :fqPacingRate: The :ref:`ds-fqpr` @@ -386,6 +395,7 @@ Request Structure "deepCachingType": "NEVER", "displayName": "demo", "dscp": 0, + "ecsEnabled": true, "geoLimit": 0, "geoProvider": 0, "initialDispersion": 1, diff --git a/docs/source/api/deliveryservices_id_safe.rst b/docs/source/api/deliveryservices_id_safe.rst index 5394d794ba..577e3d7bce 100644 --- a/docs/source/api/deliveryservices_id_safe.rst +++ b/docs/source/api/deliveryservices_id_safe.rst @@ -96,6 +96,10 @@ Response Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :exampleURLs: An array of :ref:`ds-example-urls` :fqPacingRate: The :ref:`ds-fqpr` @@ -259,7 +263,8 @@ Response Structure "xxx", "zyx" ], - "maxOriginConnections": 0 + "maxOriginConnections": 0, + "ecsEnabled": false }]} diff --git a/docs/source/api/servers_id_deliveryservices.rst b/docs/source/api/servers_id_deliveryservices.rst index bf82d3a28a..09188f00ad 100644 --- a/docs/source/api/servers_id_deliveryservices.rst +++ b/docs/source/api/servers_id_deliveryservices.rst @@ -96,6 +96,10 @@ Response Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :exampleURLs: An array of :ref:`ds-example-urls` :fqPacingRate: The :ref:`ds-fqpr` @@ -259,7 +263,8 @@ Response Structure "xxx", "zyx" ], - "maxOriginConnections": 0 + "maxOriginConnections": 0, + "ecsEnabled": false }]} diff --git a/docs/source/api/users_id_deliveryservices.rst b/docs/source/api/users_id_deliveryservices.rst index 12b93e0641..8af1960e9c 100644 --- a/docs/source/api/users_id_deliveryservices.rst +++ b/docs/source/api/users_id_deliveryservices.rst @@ -80,6 +80,10 @@ Response Structure :dnsBypassIp6: A :ref:`ds-dns-bypass-ipv6` :dnsBypassTtl: The :ref:`ds-dns-bypass-ttl` :dscp: A :ref:`ds-dscp` to be used within the :term:`Delivery Service` +:ecsEnabled: A boolean that defines the :ref:`ds-ecs` setting on this :term:`Delivery Service` + + .. versionadded:: 1.4 + :edgeHeaderRewrite: A set of :ref:`ds-edge-header-rw-rules` :exampleURLs: An array of :ref:`ds-example-urls` :fqPacingRate: The :ref:`ds-fqpr` @@ -229,7 +233,8 @@ Response Structure "trRequestHeaders": null, "consistentHashRegex": null, "consistentHashQueryParams": null, - "maxOriginConnections": null + "maxOriginConnections": null, + "ecsEnabled": false }]} .. [#tenancy] While it is totally possible to assign a :term:`Delivery Service` to a user who's :term:`Tenant` does not have permission to own said :term:`Delivery Service`, users that request this endpoint will only see :term:`Delivery Services` that their :term:`Tenant` has permission to see. This means that there's no real guarantee that the output of this endpoint shows all of the :term:`Delivery Services` assigned to the user requested, even if the user is requesting their own assigned :term:`Delivery Services`. diff --git a/docs/source/overview/delivery_services.rst b/docs/source/overview/delivery_services.rst index 8967a8a3d2..156d40cb42 100644 --- a/docs/source/overview/delivery_services.rst +++ b/docs/source/overview/delivery_services.rst @@ -189,6 +189,12 @@ This field in general contains the contents of the a configuration file used by .. tip:: Because this ultimately is the contents of an :abbr:`ATS (Apache Traffic Server)` configuration file, it can make use of the :ref:`ort-special-strings`. +.. _ds-ecs: + +EDNS0 Client Subnet Enabled +--------------------------- +A boolean value that controls whether or not EDNS0 client subnet is enabled on this Delivery Service by Traffic Router. When creating a Delivery Service in Traffic Portal, this will default to "false". + .. _ds-example-urls: Example URLs diff --git a/lib/go-tc/crconfig.go b/lib/go-tc/crconfig.go index b02e19c1c0..fbaa487de2 100644 --- a/lib/go-tc/crconfig.go +++ b/lib/go-tc/crconfig.go @@ -121,6 +121,7 @@ type CRConfigDeliveryService struct { TTLs *CRConfigTTL `json:"ttls,omitempty"` MaxDNSIPsForLocation *int `json:"maxDnsIpsForLocation,omitempty"` IP6RoutingEnabled *bool `json:"ip6RoutingEnabled,string,omitempty"` + EcsEnabled *bool `json:"ecsEnabled,string,omitempty"` RoutingName *string `json:"routingName,omitempty"` BypassDestination map[string]*CRConfigBypassDestination `json:"bypassDestination,omitempty"` DeepCachingType *DeepCachingType `json:"deepCachingType"` diff --git a/lib/go-tc/deliveryservices.go b/lib/go-tc/deliveryservices.go index 2042ae87ff..cf4bcc3733 100644 --- a/lib/go-tc/deliveryservices.go +++ b/lib/go-tc/deliveryservices.go @@ -164,6 +164,7 @@ type DeliveryServiceNullable struct { DeliveryServiceNullableV13 ConsistentHashRegex *string `json:"consistentHashRegex"` ConsistentHashQueryParams []string `json:"consistentHashQueryParams"` + EcsEnabled bool `json:"ecsEnabled" db:"ecs_enabled"` MaxOriginConnections *int `json:"maxOriginConnections" db:"max_origin_connections"` } diff --git a/traffic_ops/app/db/migrations/20191215000000_add_ecs_enabled.sql b/traffic_ops/app/db/migrations/20191215000000_add_ecs_enabled.sql new file mode 100644 index 0000000000..8e451651e0 --- /dev/null +++ b/traffic_ops/app/db/migrations/20191215000000_add_ecs_enabled.sql @@ -0,0 +1,22 @@ +/* + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +-- +goose Up +-- SQL in section 'Up' is executed when this migration is applied +ALTER TABLE deliveryservice ADD COLUMN ecs_enabled boolean NOT NULL DEFAULT false; + +-- +goose Down +-- SQL section 'Down' is executed when this migration is rolled back +ALTER TABLE deliveryservice DROP COLUMN ecs_enabled; \ No newline at end of file diff --git a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice.go b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice.go index 629a75e679..6e766a226a 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/deliveryservice.go +++ b/traffic_ops/traffic_ops_golang/crconfig/deliveryservice.go @@ -114,6 +114,7 @@ SELECT d.xml_id, d.dns_bypass_cname, d.http_bypass_fqdn, d.ipv6_routing_enabled, + d.ecs_enabled, d.deep_caching_type, d.tr_request_headers, d.tr_response_headers, @@ -165,6 +166,7 @@ AND d.active = true dnsBypassCName := sql.NullString{} httpBypassFQDN := sql.NullString{} ip6RoutingEnabled := sql.NullBool{} + ecsEnabled := sql.NullBool{} deepCachingType := sql.NullString{} trRequestHeaders := sql.NullString{} trResponseHeaders := sql.NullString{} @@ -193,6 +195,7 @@ AND d.active = true &dnsBypassCName, &httpBypassFQDN, &ip6RoutingEnabled, + &ecsEnabled, &deepCachingType, &trRequestHeaders, &trResponseHeaders, @@ -375,6 +378,7 @@ AND d.active = true } ds.IP6RoutingEnabled = &ip6RoutingEnabled.Bool // No Valid check, false if null + ds.EcsEnabled = &ecsEnabled.Bool // No Valid check, false if null if trResponseHeaders.Valid && trResponseHeaders.String != "" { trResponseHeaders.String = strings.Replace(trResponseHeaders.String, "__RETURN__", "\n", -1) diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go index c77dd73c31..a11e0e6de7 100644 --- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go +++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go @@ -255,7 +255,8 @@ func createV14(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS t &ds.TRRequestHeaders, &ds.TRResponseHeaders, &ds.TypeID, - &ds.XMLID) + &ds.XMLID, + &ds.EcsEnabled) if err != nil { usrErr, sysErr, code := api.ParseDBError(err) @@ -649,6 +650,7 @@ func updateV14(w http.ResponseWriter, r *http.Request, inf *api.APIInfo, reqDS * &ds.AnonymousBlockingEnabled, &ds.ConsistentHashRegex, &ds.MaxOriginConnections, + &ds.EcsEnabled, &ds.ID) if err != nil { @@ -988,6 +990,7 @@ func GetDeliveryServices(query string, queryValues map[string]interface{}, tx *s &ds.DNSBypassIP6, &ds.DNSBypassTTL, &ds.DSCP, + &ds.EcsEnabled, &ds.EdgeHeaderRewrite, &ds.GeoLimitRedirectURL, &ds.GeoLimit, @@ -1513,6 +1516,7 @@ ds.dns_bypass_ip, ds.dns_bypass_ip6, ds.dns_bypass_ttl, ds.dscp, +ds.ecs_enabled, ds.edge_header_rewrite, ds.geolimit_redirect_url, ds.geo_limit, @@ -1628,8 +1632,9 @@ type=$48, xml_id=$49, anonymous_blocking_enabled=$50, consistent_hash_regex=$51, -max_origin_connections=$52 -WHERE id=$53 +max_origin_connections=$52, +ecs_enabled=$53 +WHERE id=$54 RETURNING last_updated ` } @@ -1688,9 +1693,10 @@ tenant_id, tr_request_headers, tr_response_headers, type, -xml_id +xml_id, +ecs_enabled ) -VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52) +VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53) RETURNING id, last_updated ` } diff --git a/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html b/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html index 779e22493e..af1fa50e59 100644 --- a/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html +++ b/traffic_portal/app/src/common/modules/form/deliveryService/form.deliveryService.DNS.tpl.html @@ -630,6 +630,25 @@

Current Value

+ +
+ +
+ + Required + +
+
+
+ +
+ +
+ + Required + +
+
+
+ +
+ +
+ + Required + +
+
+