Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .pipelines/e2e-anc-cloud-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: $(Date:yyyyMMdd)$(Rev:.r)
# Run this gate on the PR, using a PlatformSettingsOverride
# subscription which does not auto-inject the RCV1P opt-in tag.
trigger: none
pr: none
parameters:
- name: subscriptionId
type: string
default: ""
- name: variableGroup
type: string
default: ab-e2e
variables:
TAGS_TO_RUN: "nativecloudinit=true"
SKIP_E2E_TESTS: false
REQUIRE_NATIVE_CLOUD_INTEGRATION: "true"
SKIP_TESTS_WITH_SKU_CAPACITY_ISSUE: false
DISABLE_SCRIPTLESS: false
DISABLE_SCRIPT_LESS_COMPILATION: false
E2E_GO_TEST_TIMEOUT: "85m"
jobs:
- template: ./templates/e2e-template.yaml
parameters:
name: Native Cloud Initialization Merge Gate
IgnoreScenariosWithMissingVhd: false
subscriptionId: ${{ parameters.subscriptionId }}
variableGroup: ${{ parameters.variableGroup }}
rcv1pTagsAutoInjected: false
failedTestsRetryCount: 0
jobTimeoutInMinutes: 100
19 changes: 19 additions & 0 deletions .pipelines/scripts/e2e_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ SUBSCRIPTION_ID="${SUBSCRIPTION_ID:?SUBSCRIPTION_ID or SUBSCRIPTION_ID_OVERRIDE
az account set -s "${SUBSCRIPTION_ID}"
echo "Using subscription ${SUBSCRIPTION_ID} for e2e tests"

if [ "${REQUIRE_NATIVE_CLOUD_INTEGRATION:-false}" = "true" ]; then
if [ "${RCV1P_TAGS_AUTO_INJECTED:-false}" = "true" ]; then
echo "Native cloud integration requires a subscription without auto-injected RCV1P tags" >&2
exit 1
fi
feature_state="$(az feature show --namespace Microsoft.Compute --name PlatformSettingsOverride --query properties.state --output tsv)"
if [ "$feature_state" != "Registered" ]; then
echo "Native cloud integration requires Microsoft.Compute/PlatformSettingsOverride registration" >&2
exit 1
fi
export DISABLE_SCRIPTLESS=false
export DISABLE_SCRIPT_LESS_COMPILATION=false
export TEST_PRE_PROVISION=false
export SKIP_TESTS_WITH_SKU_CAPACITY_ISSUE=false
export IGNORE_SCENARIOS_WITH_MISSING_VHD=false
export TAGS_TO_RUN="nativecloudinit=true"
export TAGS_TO_SKIP=""
fi

# Setup go
GOPATH="$(go env GOPATH | tr -d "'\"")"
export GOPATH
Expand Down
9 changes: 9 additions & 0 deletions aks-node-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ Native initialization and periodic refresh emit guest-agent events through
`EventLogger` using `CloudInitialization`, `CloudRepositoryInitialization`, and
`CloudCertificateRefresh` task suffixes, alongside the existing ANC logs.

##### Real-VM validation

The [native cloud-initialization E2E gate](../e2e/README.md#native-cloud-initialization-integration-gate)
runs on Ubuntu 22.04 and Azure Linux 3, with the PR-built ANC installed as both
the VHD binary that runs `init-cloud` and the provisioning hotfix, and actual
provisioning through Node Ready. The temporary-root/mock-command tests in this
module remain unit/component coverage, not VM acceptance. The production
WireServer default is unchanged and VM provisioning uses the real Azure endpoint.

### Validating and normalizing AKSNodeConfig

Before serializing a typed config, producers such as RP should call:
Expand Down
169 changes: 169 additions & 0 deletions aks-node-controller/testutil/cloudfixture/repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Package cloudfixture contains services used only by cloud initialization tests.
package cloudfixture

import (
"encoding/json"
"net/http"
"net/http/httputil"
"net/url"
"runtime"
"strings"
"sync"
"time"
)

const StatsPath = "/anc-integration/stats"

const ubuntuPrefix = "/ubuntu"
const microsoftPrefix = "/microsoft"
const repositoryHTTPScheme = "https"

type RepositoryStats struct {
Keys int `json:"keys"`
Metadata int `json:"metadata"`
Failures int `json:"failures"`
}

// RepositoryProxy preserves vendor signatures and package contents. In particular,
// it must not replace real repository metadata with a successful empty response.
type RepositoryProxy struct {
ubuntu, microsoft *url.URL
mu sync.Mutex
stats RepositoryStats
failMetadata bool
}

func NewRepositoryProxy() *RepositoryProxy {
// Azure VMs use this mirror by default, and the E2E egress firewall allows it only
// over HTTP. apt still verifies the vendor-signed metadata.
ubuntu := &url.URL{Scheme: "http", Host: "azure.archive.ubuntu.com", Path: ubuntuPrefix}
if runtime.GOARCH == "arm64" {
ubuntu = &url.URL{Scheme: repositoryHTTPScheme, Host: "ports.ubuntu.com", Path: "/ubuntu-ports"}
}
return &RepositoryProxy{
ubuntu: ubuntu,
microsoft: &url.URL{Scheme: repositoryHTTPScheme, Host: "packages.microsoft.com"},
}
}

func (p *RepositoryProxy) Stats() RepositoryStats {
p.mu.Lock()
defer p.mu.Unlock()
return p.stats
}

func (p *RepositoryProxy) SetMetadataFailure(fail bool) {
p.mu.Lock()
defer p.mu.Unlock()
p.failMetadata = fail
}

func (p *RepositoryProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "only GET and HEAD are supported", http.StatusMethodNotAllowed)
return
}
p.mu.Lock()
fail := p.failMetadata && isRepositoryMetadata(r.URL.Path)
p.mu.Unlock()
if fail {
p.record(r.URL.Path, http.StatusServiceUnavailable)
http.Error(w, "injected repository metadata outage", http.StatusServiceUnavailable)
return
}
if r.URL.Path == StatsPath {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(p.Stats()); err != nil {
return // The caller has disconnected.
}
return
}
target, prefix := p.microsoft, ""
switch {
case strings.HasPrefix(r.URL.Path, ubuntuPrefix+"/"):
target, prefix = p.ubuntu, ubuntuPrefix
case strings.HasPrefix(r.URL.Path, microsoftPrefix+"/"):
prefix = microsoftPrefix
case strings.HasPrefix(r.URL.Path, "/keys/"), strings.HasPrefix(r.URL.Path, "/azurelinux/"):
default:
http.NotFound(w, r)
return
}
requestPath := r.URL.Path
proxy := &httputil.ReverseProxy{
Rewrite: func(pr *httputil.ProxyRequest) {
pr.Out.URL.Path = strings.TrimPrefix(pr.In.URL.Path, prefix)
pr.Out.URL.RawPath = ""
pr.SetURL(target)
pr.Out.Header.Del("Authorization")
pr.Out.Header.Del("Cookie")
},
ModifyResponse: func(response *http.Response) error {
if err := rewriteRepositoryRedirect(response, target, prefix); err != nil {
return err
}
p.record(requestPath, response.StatusCode)
return nil
},
ErrorHandler: func(w http.ResponseWriter, _ *http.Request, err error) {
p.record(requestPath, http.StatusBadGateway)
http.Error(w, "repository upstream failed: "+err.Error(), http.StatusBadGateway)
},
}
proxy.ServeHTTP(w, r)
}

func rewriteRepositoryRedirect(response *http.Response, target *url.URL, prefix string) error {
location := response.Header.Get("Location")
if location == "" {
return nil
}
redirect, err := url.Parse(location)
if err != nil {
return err
}
if redirect.Host != "" && redirect.Host != target.Host {
return nil
}
redirect.Scheme, redirect.Host = "", ""
switch prefix {
case microsoftPrefix:
redirect.Path = prefix + redirect.Path
case ubuntuPrefix:
redirect.Path = prefix + strings.TrimPrefix(redirect.Path, target.Path)
}
response.Header.Set("Location", redirect.String())
return nil
}

func (p *RepositoryProxy) record(path string, status int) {
p.mu.Lock()
defer p.mu.Unlock()
if status >= 400 {
p.stats.Failures++
return
}
if status < 200 || status >= 300 {
return
}
if strings.HasPrefix(path, "/keys/") {
p.stats.Keys++
}
if isRepositoryMetadata(path) {
p.stats.Metadata++
}
}

func isRepositoryMetadata(path string) bool {
return strings.HasSuffix(path, "/InRelease") || strings.HasSuffix(path, "/Release") ||
strings.HasSuffix(path, "/repodata/repomd.xml")
}

func NewHTTPServer(address string, handler http.Handler) *http.Server {
return &http.Server{
Addr: address,
Handler: handler,
ReadHeaderTimeout: 10 * time.Second,
IdleTimeout: 30 * time.Second,
}
}
109 changes: 109 additions & 0 deletions aks-node-controller/testutil/cloudfixture/repository_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cloudfixture

import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRepositoryProxyPreservesVendorContent(t *testing.T) {
var paths []string
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
paths = append(paths, r.URL.Path)
assert.Empty(t, r.Header.Get("Authorization"))
assert.Empty(t, r.Header.Get("Cookie"))
if r.URL.Path == "/ubuntu/missing" {
http.NotFound(w, r)
return
}
_, err := io.WriteString(w, "unchanged vendor-signed content")
assert.NoError(t, err)
}))
defer upstream.Close()
target, err := url.Parse(upstream.URL)
require.NoError(t, err)
ubuntu := *target
ubuntu.Path = "/ubuntu"
proxy := &RepositoryProxy{ubuntu: &ubuntu, microsoft: target}
server := httptest.NewServer(proxy)
defer server.Close()
for _, path := range []string{
"/ubuntu/dists/jammy/InRelease",
"/microsoft/ubuntu/22.04/prod/dists/jammy/Release",
"/keys/microsoft.asc",
"/azurelinux/3.0/prod/base/x86_64/repodata/repomd.xml",
} {
request, requestErr := http.NewRequest(http.MethodGet, server.URL+path, nil)
require.NoError(t, requestErr)
request.Header.Set("Authorization", "must-not-be-forwarded")
request.Header.Set("Cookie", "must-not-be-forwarded")
response, responseErr := server.Client().Do(request)
require.NoError(t, responseErr)
body, readErr := io.ReadAll(response.Body)
require.NoError(t, readErr)
require.NoError(t, response.Body.Close())
require.Equal(t, http.StatusOK, response.StatusCode)
require.Equal(t, "unchanged vendor-signed content", string(body))
}
require.Equal(t, []string{
"/ubuntu/dists/jammy/InRelease",
"/ubuntu/22.04/prod/dists/jammy/Release",
"/keys/microsoft.asc",
"/azurelinux/3.0/prod/base/x86_64/repodata/repomd.xml",
}, paths)
require.Equal(t, RepositoryStats{Keys: 1, Metadata: 3}, proxy.Stats())
response, err := server.Client().Get(server.URL + "/ubuntu/missing")
require.NoError(t, err)
require.NoError(t, response.Body.Close())
require.Equal(t, http.StatusNotFound, response.StatusCode)
require.Equal(t, 1, proxy.Stats().Failures)
}

func TestRepositoryProxyRejectsUnrelatedPathsAndMethods(t *testing.T) {
proxy := NewRepositoryProxy()
for _, test := range []struct {
method, path string
status int
}{
{http.MethodGet, "/arbitrary-upstream", http.StatusNotFound},
{http.MethodPost, "/keys/microsoft.asc", http.StatusMethodNotAllowed},
{http.MethodGet, StatsPath, http.StatusOK},
} {
response := httptest.NewRecorder()
proxy.ServeHTTP(response, httptest.NewRequest(test.method, test.path, nil))
require.Equal(t, test.status, response.Code)
}
require.Equal(t, RepositoryStats{}, proxy.Stats())
}

func TestRepositoryProxyKeepsRedirectsOnFixture(t *testing.T) {
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/ubuntu/22.04/prod/", http.StatusMovedPermanently)
}))
defer upstream.Close()
target, err := url.Parse(upstream.URL)
require.NoError(t, err)
proxy := &RepositoryProxy{ubuntu: target, microsoft: target}
response := httptest.NewRecorder()
proxy.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/microsoft/ubuntu/22.04/prod", nil))
require.Equal(t, http.StatusMovedPermanently, response.Code)
require.Equal(t, "/microsoft/ubuntu/22.04/prod/", response.Header().Get("Location"))
}

func TestRepositoryMetadataFailureIsExplicitAndRecoverable(t *testing.T) {
proxy := NewRepositoryProxy()
proxy.SetMetadataFailure(true)
response := httptest.NewRecorder()
proxy.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/ubuntu/dists/jammy/InRelease", nil))
require.Equal(t, http.StatusServiceUnavailable, response.Code)
require.Equal(t, RepositoryStats{Failures: 1}, proxy.Stats())
proxy.SetMetadataFailure(false)
response = httptest.NewRecorder()
proxy.ServeHTTP(response, httptest.NewRequest(http.MethodGet, StatsPath, nil))
require.Equal(t, http.StatusOK, response.Code)
}
Loading
Loading