-
Notifications
You must be signed in to change notification settings - Fork 91
fix(#6615): auto-add GitLab forge host to sandbox egress allowlist and proxy profile #6616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
|
|
||
| "gopkg.in/yaml.v3" | ||
|
|
||
| gl "github.com/fullsend-ai/fullsend/internal/forge/gitlab" | ||
| ) | ||
|
|
||
| // gitlabForgeEndpoint is the YAML shape of a single provider endpoint. | ||
| type gitlabForgeEndpoint struct { | ||
| Host string `yaml:"host"` | ||
| Port int `yaml:"port"` | ||
| Protocol string `yaml:"protocol"` | ||
| Access string `yaml:"access"` | ||
| Enforcement string `yaml:"enforcement"` | ||
| } | ||
|
|
||
| // gitlabForgeProfileSpec is the YAML shape of a provider profile. | ||
| type gitlabForgeProfileSpec struct { | ||
| ID string `yaml:"id"` | ||
| DisplayName string `yaml:"display_name"` | ||
| Description string `yaml:"description"` | ||
| Category string `yaml:"category"` | ||
| Endpoints []gitlabForgeEndpoint `yaml:"endpoints"` | ||
| Binaries []string `yaml:"binaries"` | ||
| } | ||
|
|
||
| // generateGitLabForgeProfile creates a temporary provider profile YAML | ||
| // for the GitLab forge host, analogous to the scaffold's | ||
| // fullsend-github.yaml. Returns the temp file path and a cleanup | ||
| // function, or ("", nil, nil) when no GitLab host can be resolved. | ||
| func generateGitLabForgeProfile() (string, func(), error) { | ||
| host, port := gl.ResolveForgeHostPort() | ||
| if host == "" { | ||
| return "", nil, nil | ||
| } | ||
| portNum, err := strconv.Atoi(port) | ||
| if err != nil { | ||
| return "", nil, fmt.Errorf("GitLab port %q is not a valid integer", port) | ||
| } | ||
|
|
||
| profile := gitlabForgeProfileSpec{ | ||
| ID: "fullsend-gitlab-forge", | ||
| DisplayName: "Fullsend GitLab (auto)", | ||
| Description: "GitLab API and Git operations for fullsend agents (auto-generated from forge host)", | ||
| Category: "source_control", | ||
| Endpoints: []gitlabForgeEndpoint{ | ||
| {Host: host, Port: portNum, Protocol: "rest", Access: "read-write", Enforcement: "enforce"}, | ||
| }, | ||
| Binaries: []string{"**/git", "**/glab", "**/node", "**/pre-commit"}, | ||
| } | ||
|
|
||
| var buf bytes.Buffer | ||
| enc := yaml.NewEncoder(&buf) | ||
| enc.SetIndent(2) | ||
| if err := enc.Encode(&profile); err != nil { | ||
| return "", nil, fmt.Errorf("marshaling GitLab profile YAML: %w", err) | ||
| } | ||
| if err := enc.Close(); err != nil { | ||
| return "", nil, fmt.Errorf("closing YAML encoder: %w", err) | ||
| } | ||
|
|
||
| tmpDir, err := os.MkdirTemp("", "fullsend-gitlab-profile-*") | ||
| if err != nil { | ||
| return "", nil, fmt.Errorf("creating temp dir for GitLab profile: %w", err) | ||
| } | ||
| profilePath := filepath.Join(tmpDir, "fullsend-gitlab-forge.yaml") | ||
| if err := os.WriteFile(profilePath, buf.Bytes(), 0o644); err != nil { | ||
| os.RemoveAll(tmpDir) | ||
| return "", nil, fmt.Errorf("writing GitLab profile: %w", err) | ||
| } | ||
| return profilePath, func() { os.RemoveAll(tmpDir) }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGenerateGitLabForgeProfile(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| env map[string]string | ||
| wantEmpty bool | ||
| wantErr string | ||
| wantHost string | ||
| wantPort string | ||
| notContains string | ||
| }{ | ||
| { | ||
| name: "default port from CI_SERVER_URL", | ||
| env: map[string]string{"CI_SERVER_URL": "https://gitlab.cee.redhat.com"}, | ||
| wantHost: "host: gitlab.cee.redhat.com", | ||
| wantPort: "port: 443", | ||
| }, | ||
| { | ||
| name: "non-standard port", | ||
| env: map[string]string{"CI_SERVER_URL": "https://gitlab.company.com:8443"}, | ||
| wantHost: "host: gitlab.company.com", | ||
| wantPort: "port: 8443", | ||
| }, | ||
| { | ||
| name: "no env vars", | ||
| env: map[string]string{}, | ||
| wantEmpty: true, | ||
| }, | ||
| { | ||
| name: "FULLSEND_GITLAB_URL takes precedence", | ||
| env: map[string]string{"FULLSEND_GITLAB_URL": "https://gitlab.company.com", "CI_SERVER_URL": "https://gitlab.other.com"}, | ||
| wantHost: "host: gitlab.company.com", | ||
| wantPort: "port: 443", | ||
| notContains: "gitlab.other.com", | ||
| }, | ||
| { | ||
| name: "gitlab.com", | ||
| env: map[string]string{"CI_SERVER_URL": "https://gitlab.com"}, | ||
| wantHost: "host: gitlab.com", | ||
| wantPort: "port: 443", | ||
| }, | ||
| { | ||
| name: "http scheme defaults to port 80", | ||
| env: map[string]string{"CI_SERVER_URL": "http://gitlab.internal"}, | ||
| wantHost: "host: gitlab.internal", | ||
| wantPort: "port: 80", | ||
| }, | ||
| { | ||
| name: "invalid URL yields empty result", | ||
| env: map[string]string{"CI_SERVER_URL": "https://gitlab.company.com:notaport"}, | ||
| wantEmpty: true, | ||
| }, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| for _, key := range []string{"FULLSEND_GITLAB_URL", "GITLAB_API_URL", "CI_SERVER_URL"} { | ||
| t.Setenv(key, "") | ||
| } | ||
| for k, v := range tc.env { | ||
| t.Setenv(k, v) | ||
| } | ||
|
|
||
| profilePath, cleanup, err := generateGitLabForgeProfile() | ||
| if tc.wantErr != "" { | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), tc.wantErr) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
|
|
||
| if tc.wantEmpty { | ||
| assert.Empty(t, profilePath) | ||
| assert.Nil(t, cleanup) | ||
| return | ||
| } | ||
|
|
||
| require.NotEmpty(t, profilePath) | ||
| defer cleanup() | ||
|
|
||
| data, err := os.ReadFile(profilePath) | ||
| require.NoError(t, err) | ||
| content := string(data) | ||
| assert.Contains(t, content, "id: fullsend-gitlab-forge") | ||
| assert.Contains(t, content, tc.wantHost) | ||
| assert.Contains(t, content, tc.wantPort) | ||
| assert.Contains(t, content, "category: source_control") | ||
| assert.Contains(t, content, "**/node") | ||
| if tc.notContains != "" { | ||
| assert.NotContains(t, content, tc.notContains) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package gitlab | ||
|
|
||
| import ( | ||
| "net/url" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| // URLEnvVars is the ordered list of environment variables consulted | ||
| // to resolve the GitLab instance URL. Precedence matches forge_client.go. | ||
| var URLEnvVars = []string{"FULLSEND_GITLAB_URL", "GITLAB_API_URL", "CI_SERVER_URL"} | ||
|
ggallen marked this conversation as resolved.
ggallen marked this conversation as resolved.
ggallen marked this conversation as resolved.
ggallen marked this conversation as resolved.
|
||
|
|
||
|
ggallen marked this conversation as resolved.
ggallen marked this conversation as resolved.
|
||
| // ResolveForgeHostPort returns the GitLab forge hostname and port from | ||
| // environment variables. URL precedence matches forge_client.go: | ||
| // FULLSEND_GITLAB_URL > GITLAB_API_URL > CI_SERVER_URL. | ||
| // When the URL does not include an explicit port, the default is | ||
| // derived from the scheme ("80" for http, "443" otherwise). | ||
| // Returns ("", "") when no URL can be resolved. | ||
| func ResolveForgeHostPort() (host, port string) { | ||
| for _, env := range URLEnvVars { | ||
| raw := strings.TrimSpace(os.Getenv(env)) | ||
| if raw == "" { | ||
| continue | ||
| } | ||
| u, err := url.Parse(raw) | ||
|
ggallen marked this conversation as resolved.
ggallen marked this conversation as resolved.
|
||
| if err != nil || u.Hostname() == "" { | ||
| continue | ||
| } | ||
| p := u.Port() | ||
| if p == "" { | ||
| if u.Scheme == "http" { | ||
| p = "80" | ||
| } else { | ||
| p = "443" | ||
| } | ||
| } | ||
| return u.Hostname(), p | ||
| } | ||
| return "", "" | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.