tag v0.155.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.155.0 ---------------- * Fedora 43: add shadow-utils when LockRoot is enabled, update cloud-init service name (osbuild/images#1618) * Author: Achilleas Koutsou, Reviewers: Gianluca Zuccarelli, Michael Vogt * Update osbuild dependency commit ID to latest (osbuild/images#1609) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Simon de Vlieger, Tomáš Hozza * Update snapshots to 20250626 (osbuild/images#1623) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Simon de Vlieger * distro/rhel9: xz compress azure-cvm image type [HMS-8587] (osbuild/images#1620) * Author: Achilleas Koutsou, Reviewers: Simon de Vlieger, Tomáš Hozza * distro/rhel: introduce new image type: Azure SAP Apps [HMS-8738] (osbuild/images#1612) * Author: Achilleas Koutsou, Reviewers: Simon de Vlieger, Tomáš Hozza * distro/rhel: move ansible-core to sap_extras_pkgset (osbuild/images#1624) * Author: Achilleas Koutsou, Reviewers: Brian C. Lane, Tomáš Hozza * github/create-tag: allow passing the version when run manually (osbuild/images#1621) * Author: Achilleas Koutsou, Reviewers: Lukáš Zapletal, Tomáš Hozza * rhel9: move image-config into pure YAML (HMS-8593) (osbuild/images#1616) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * test: split manifest checksums into separate files (osbuild/images#1625) * Author: Achilleas Koutsou, Reviewers: Simon de Vlieger, Tomáš Hozza — Somewhere on the Internet, 2025-06-30 --- tag v0.156.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.156.0 ---------------- * Many: delete repositories for EOL distributions (HMS-7044) (osbuild/images#1607) * Author: Tomáš Hozza, Reviewers: Michael Vogt, Simon de Vlieger * RHSM/facts: add 'image-builder CLI' API type (osbuild/images#1640) * Author: Tomáš Hozza, Reviewers: Brian C. Lane, Simon de Vlieger * Update dependencies 2025-06-29 (osbuild/images#1628) * Author: SchutzBot, Reviewers: Simon de Vlieger, Tomáš Hozza * Update osbuild dependency commit ID to latest (osbuild/images#1627) * Author: SchutzBot, Reviewers: Simon de Vlieger, Tomáš Hozza * [RFC] image: drop `InstallWeakDeps` from image.DiskImage (osbuild/images#1642) * Author: Michael Vogt, Reviewers: Brian C. Lane, Simon de Vlieger, Tomáš Hozza * build(deps): bump the go-deps group across 1 directory with 3 updates (osbuild/images#1632) * Author: dependabot[bot], Reviewers: SchutzBot, Tomáš Hozza * distro/rhel10: xz compress azure-cvm image type (osbuild/images#1638) * Author: Achilleas Koutsou, Reviewers: Brian C. Lane, Simon de Vlieger * distro: cleanup/refactor distro/{defs,generic} (HMS-8744) (osbuild/images#1570) * Author: Michael Vogt, Reviewers: Simon de Vlieger, Tomáš Hozza * distro: remove some hardcoded values from generic/images.go (osbuild/images#1636) * Author: Michael Vogt, Reviewers: Simon de Vlieger, Tomáš Hozza * distro: small tweaks for the YAML based imagetypes (osbuild/images#1622) * Author: Michael Vogt, Reviewers: Brian C. Lane, Simon de Vlieger * fedora/wsl: packages and locale (osbuild/images#1635) * Author: Simon de Vlieger, Reviewers: Michael Vogt, Tomáš Hozza * image/many: make compression more generic (osbuild/images#1634) * Author: Simon de Vlieger, Reviewers: Brian C. Lane, Michael Vogt * manifest: handle content template name with spaces (osbuild/images#1641) * Author: Bryttanie, Reviewers: Brian C. Lane, Michael Vogt, Tomáš Hozza * many: implement gzip (osbuild/images#1633) * Author: Simon de Vlieger, Reviewers: Michael Vogt, Tomáš Hozza * rhel/azure: set GRUB_TERMINAL based on architecture [RHEL-91383] (osbuild/images#1626) * Author: Achilleas Koutsou, Reviewers: Simon de Vlieger, Tomáš Hozza — Somewhere on the Internet, 2025-07-07 ---
177 lines
5.8 KiB
Go
177 lines
5.8 KiB
Go
// Copyright 2023 Google LLC
|
|
//
|
|
// 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.
|
|
|
|
package grpctransport
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"cloud.google.com/go/auth"
|
|
"cloud.google.com/go/auth/credentials"
|
|
"cloud.google.com/go/auth/internal/compute"
|
|
"golang.org/x/time/rate"
|
|
"google.golang.org/grpc"
|
|
grpcgoogle "google.golang.org/grpc/credentials/google"
|
|
)
|
|
|
|
var logRateLimiter = rate.Sometimes{Interval: 1 * time.Second}
|
|
|
|
func isDirectPathEnabled(endpoint string, opts *Options) bool {
|
|
if opts.InternalOptions != nil && !opts.InternalOptions.EnableDirectPath {
|
|
return false
|
|
}
|
|
if !checkDirectPathEndPoint(endpoint) {
|
|
return false
|
|
}
|
|
if b, _ := strconv.ParseBool(os.Getenv(disableDirectPathEnvVar)); b {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func checkDirectPathEndPoint(endpoint string) bool {
|
|
// Only [dns:///]host[:port] is supported, not other schemes (e.g., "tcp://" or "unix://").
|
|
// Also don't try direct path if the user has chosen an alternate name resolver
|
|
// (i.e., via ":///" prefix).
|
|
if strings.Contains(endpoint, "://") && !strings.HasPrefix(endpoint, "dns:///") {
|
|
return false
|
|
}
|
|
|
|
if endpoint == "" {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func isTokenProviderComputeEngine(tp auth.TokenProvider) bool {
|
|
if tp == nil {
|
|
return false
|
|
}
|
|
tok, err := tp.Token(context.Background())
|
|
if err != nil {
|
|
return false
|
|
}
|
|
if tok == nil {
|
|
return false
|
|
}
|
|
if tok.MetadataString("auth.google.tokenSource") != "compute-metadata" {
|
|
return false
|
|
}
|
|
if tok.MetadataString("auth.google.serviceAccount") != "default" {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func isTokenProviderDirectPathCompatible(tp auth.TokenProvider, o *Options) bool {
|
|
if tp == nil {
|
|
return false
|
|
}
|
|
if o.InternalOptions != nil && o.InternalOptions.EnableNonDefaultSAForDirectPath {
|
|
return true
|
|
}
|
|
return isTokenProviderComputeEngine(tp)
|
|
}
|
|
|
|
func isDirectPathXdsUsed(o *Options) bool {
|
|
// Method 1: Enable DirectPath xDS by env;
|
|
if b, _ := strconv.ParseBool(os.Getenv(enableDirectPathXdsEnvVar)); b {
|
|
return true
|
|
}
|
|
// Method 2: Enable DirectPath xDS by option;
|
|
if o.InternalOptions != nil && o.InternalOptions.EnableDirectPathXds {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func isDirectPathBoundTokenEnabled(opts *InternalOptions) bool {
|
|
for _, ev := range opts.AllowHardBoundTokens {
|
|
if ev == "ALTS" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// configureDirectPath returns some dial options and an endpoint to use if the
|
|
// configuration allows the use of direct path. If it does not the provided
|
|
// grpcOpts and endpoint are returned.
|
|
func configureDirectPath(grpcOpts []grpc.DialOption, opts *Options, endpoint string, creds *auth.Credentials) ([]grpc.DialOption, string, error) {
|
|
logRateLimiter.Do(func() {
|
|
logDirectPathMisconfig(endpoint, creds, opts)
|
|
})
|
|
if isDirectPathEnabled(endpoint, opts) && compute.OnComputeEngine() && isTokenProviderDirectPathCompatible(creds, opts) {
|
|
// Overwrite all of the previously specific DialOptions, DirectPath uses its own set of credentials and certificates.
|
|
defaultCredetialsOptions := grpcgoogle.DefaultCredentialsOptions{PerRPCCreds: &grpcCredentialsProvider{creds: creds}}
|
|
if isDirectPathBoundTokenEnabled(opts.InternalOptions) && isTokenProviderComputeEngine(creds) {
|
|
optsClone := opts.resolveDetectOptions()
|
|
optsClone.TokenBindingType = credentials.ALTSHardBinding
|
|
altsCreds, err := credentials.DetectDefault(optsClone)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
defaultCredetialsOptions.ALTSPerRPCCreds = &grpcCredentialsProvider{creds: altsCreds}
|
|
}
|
|
grpcOpts = []grpc.DialOption{
|
|
grpc.WithCredentialsBundle(grpcgoogle.NewDefaultCredentialsWithOptions(defaultCredetialsOptions))}
|
|
if timeoutDialerOption != nil {
|
|
grpcOpts = append(grpcOpts, timeoutDialerOption)
|
|
}
|
|
// Check if google-c2p resolver is enabled for DirectPath
|
|
if isDirectPathXdsUsed(opts) {
|
|
// google-c2p resolver target must not have a port number
|
|
if addr, _, err := net.SplitHostPort(endpoint); err == nil {
|
|
endpoint = "google-c2p:///" + addr
|
|
} else {
|
|
endpoint = "google-c2p:///" + endpoint
|
|
}
|
|
} else {
|
|
if !strings.HasPrefix(endpoint, "dns:///") {
|
|
endpoint = "dns:///" + endpoint
|
|
}
|
|
grpcOpts = append(grpcOpts,
|
|
// For now all DirectPath go clients will be using the following lb config, but in future
|
|
// when different services need different configs, then we should change this to a
|
|
// per-service config.
|
|
grpc.WithDisableServiceConfig(),
|
|
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"grpclb":{"childPolicy":[{"pick_first":{}}]}}]}`))
|
|
}
|
|
// TODO: add support for system parameters (quota project, request reason) via chained interceptor.
|
|
}
|
|
return grpcOpts, endpoint, nil
|
|
}
|
|
|
|
func logDirectPathMisconfig(endpoint string, creds *auth.Credentials, o *Options) {
|
|
|
|
// Case 1: does not enable DirectPath
|
|
if !isDirectPathEnabled(endpoint, o) {
|
|
o.logger().Warn("DirectPath is disabled. To enable, please set the EnableDirectPath option along with the EnableDirectPathXds option.")
|
|
} else {
|
|
// Case 2: credential is not correctly set
|
|
if !isTokenProviderDirectPathCompatible(creds, o) {
|
|
o.logger().Warn("DirectPath is disabled. Please make sure the token source is fetched from GCE metadata server and the default service account is used.")
|
|
}
|
|
// Case 3: not running on GCE
|
|
if !compute.OnComputeEngine() {
|
|
o.logger().Warn("DirectPath is disabled. DirectPath is only available in a GCE environment.")
|
|
}
|
|
}
|
|
}
|