|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# |
| 4 | +# Cookbook:: aws-parallelcluster |
| 5 | +# Recipe:: detect_proxy |
| 6 | +# |
| 7 | +# Copyright:: 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the |
| 10 | +# License. A copy of the License is located at |
| 11 | +# |
| 12 | +# http://aws.amazon.com/apache2.0/ |
| 13 | +# |
| 14 | +# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 15 | +# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +# This recipe configures proxy environment variables for build-image in isolated networks. |
| 19 | +# |
| 20 | +# It reads the proxy URL from node['cluster']['install_proxy_url'] (set via ExtraChefAttributes) |
| 21 | +# and configures http_proxy/https_proxy ENV vars for the Chef run. This makes all subsequent |
| 22 | +# Chef resources (remote_file, bash, execute, etc.) use the explicit proxy for HTTPS traffic |
| 23 | +# instead of trying direct connections that would fail in an isolated network. |
| 24 | +# |
| 25 | +# The no_proxy list excludes S3 endpoints so downloads from S3 go through the VPC Gateway |
| 26 | +# Endpoint directly, not through the proxy. |
| 27 | +# S3 endpoints are excluded so cookbook/dependency downloads from S3 go through |
| 28 | +# the S3 VPC Gateway Endpoint directly, not through the proxy. |
| 29 | + # Both regional (s3.{region}.amazonaws.com) and global (s3.amazonaws.com) endpoints |
| 30 | + # are included because some resources use the global endpoint (e.g., cloudformation-examples |
| 31 | + # bucket uses https://s3.amazonaws.com/cloudformation-examples/...). |
| 32 | + # Note: only the regional S3 endpoint is in no_proxy because the S3 VPC Gateway Endpoint |
| 33 | + # handles regional endpoints correctly. The global s3.amazonaws.com endpoint does NOT work |
| 34 | + # through the VPC Gateway Endpoint (SSL errors), so it is intentionally left out of no_proxy |
| 35 | + # and instead goes through the proxy which has internet access. The proxy allowlist in |
| 36 | + # proxy_stack.yaml must include s3.amazonaws.com for this to work. |
| 37 | + # IMDS (169.254.169.254) and ECS task metadata (169.254.170.2) are also excluded. |
| 38 | +# |
| 39 | +# This recipe only runs when install_proxy_url is set — normal builds are unaffected. |
| 40 | + |
| 41 | +ruby_block 'configure proxy from install_proxy_url' do |
| 42 | + block do |
| 43 | + proxy_url = node['cluster']['install_proxy_url'] |
| 44 | + |
| 45 | + if proxy_url && !proxy_url.empty? |
| 46 | + region = node['cluster']['region'] |
| 47 | + |
| 48 | + # S3 endpoints bypass the proxy and use the VPC Gateway Endpoint. |
| 49 | + # Includes regional (s3.{region}), dash-style (s3-{region}), global (s3.amazonaws.com), |
| 50 | + # and dualstack (s3.dualstack.{region}) variants used by different AWS services and repos. |
| 51 | + no_proxy = [ |
| 52 | + "localhost", |
| 53 | + "127.0.0.1", |
| 54 | + "169.254.169.254", |
| 55 | + "169.254.170.2", |
| 56 | + ".s3.#{region}.amazonaws.com", |
| 57 | + "s3.#{region}.amazonaws.com", |
| 58 | + ".s3-#{region}.amazonaws.com", |
| 59 | + "s3-#{region}.amazonaws.com", |
| 60 | + ".s3.amazonaws.com", |
| 61 | + ".s3.dualstack.#{region}.amazonaws.com", |
| 62 | + "s3.dualstack.#{region}.amazonaws.com", |
| 63 | + ].join(",") |
| 64 | + |
| 65 | + Chef::Log.info("Configuring proxy: #{proxy_url}") |
| 66 | + |
| 67 | + ENV['http_proxy'] = proxy_url |
| 68 | + ENV['https_proxy'] = proxy_url |
| 69 | + ENV['HTTP_PROXY'] = proxy_url |
| 70 | + ENV['HTTPS_PROXY'] = proxy_url |
| 71 | + ENV['no_proxy'] = no_proxy |
| 72 | + ENV['NO_PROXY'] = no_proxy |
| 73 | + else |
| 74 | + Chef::Log.info("No install_proxy_url set, skipping proxy configuration") |
| 75 | + end |
| 76 | + end |
| 77 | +end |
0 commit comments