Skip to content
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

We added a custom header feature to enable communication even when using authentication software to connect to the panel. #209

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
pclient := remote.New(
config.Get().PanelLocation,
remote.WithCredentials(config.Get().AuthenticationTokenId, config.Get().AuthenticationToken),
remote.WithCustomHeader(config.Get().RemoteQuery.CustomHeaders),
remote.WithHttpClient(&http.Client{
Timeout: time.Second * time.Duration(config.Get().RemoteQuery.Timeout),
}),
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ type RemoteQueryConfiguration struct {
// 50 servers is likely just as quick as two for 100 or one for 400, and will certainly
// be less likely to cause performance issues on the Panel.
BootServersPerPage int `default:"50" yaml:"boot_servers_per_page"`

//When using services like Cloudflare Access to manage access to
//a specific system via an external authentication system,
//it is possible to add special headers to bypass authentication.
//The mentioned headers can be appended to queries sent from Wings to the panel.
CustomHeaders map[string]string `yaml:"custom_headers"`
}

// SystemConfiguration defines basic system configuration settings.
Expand Down
12 changes: 12 additions & 0 deletions remote/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type client struct {
tokenId string
token string
maxAttempts int
customHeaders map[string]string
}

// New returns a new HTTP request client that is used for making authenticated
Expand Down Expand Up @@ -68,6 +69,13 @@ func WithCredentials(id, token string) ClientOption {
}
}

// WithCustomHeader sets custom headers to be used when making remote requests.
func WithCustomHeader(headers map[string]string) ClientOption {
return func(c *client) {
c.customHeaders = headers
}
}

// WithHttpClient sets the underlying HTTP client instance to use when making
// requests to the Panel API.
func WithHttpClient(httpClient *http.Client) ClientOption {
Expand Down Expand Up @@ -109,6 +117,10 @@ func (c *client) requestOnce(ctx context.Context, method, path string, body io.R
req.Header.Set("Accept", "application/vnd.pterodactyl.v1+json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s.%s", c.tokenId, c.token))

for cHeaderKey, cHeaderValue := range c.customHeaders {
req.Header.Set(cHeaderKey, cHeaderValue)
}

// Call all opts functions to allow modifying the request
for _, o := range opts {
Expand Down