Skip to content

Commit

Permalink
Remove PGP endpoint auth requirement (#4256)
Browse files Browse the repository at this point in the history
Remove PGP endpoint auth requirement
  • Loading branch information
michel-laterman authored Dec 31, 2024
1 parent 198b2fb commit 4915d7c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: Remove auth requirement from PGP key endpoint

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: fleet-server

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
issue: https://github.com/elastic/fleet-server/issues/4255
12 changes: 2 additions & 10 deletions internal/pkg/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"strings"
"time"

"go.elastic.co/apm/v2"

"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
"github.com/elastic/fleet-server/v7/internal/pkg/dl"
"github.com/elastic/fleet-server/v7/internal/pkg/es"
Expand All @@ -22,7 +24,6 @@ import (
"github.com/elastic/fleet-server/v7/internal/pkg/file/uploader"
"github.com/elastic/fleet-server/v7/internal/pkg/limit"
"github.com/elastic/fleet-server/v7/internal/pkg/logger"
"go.elastic.co/apm/v2"

"github.com/rs/zerolog"
"github.com/rs/zerolog/hlog"
Expand Down Expand Up @@ -252,15 +253,6 @@ func NewHTTPErrResp(err error) HTTPErrResp {
zerolog.InfoLevel,
},
},
{
ErrPGPPermissions,
HTTPErrResp{
http.StatusInternalServerError,
"ErrPGPPermissions",
"fleet-server PGP key has incorrect permissions",
zerolog.ErrorLevel,
},
},
// apikey
{
apikey.ErrNoAuthHeader,
Expand Down
12 changes: 5 additions & 7 deletions internal/pkg/api/handlePGPRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
"os"
"path/filepath"

"github.com/rs/zerolog"
"go.elastic.co/apm/v2"

"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
"github.com/elastic/fleet-server/v7/internal/pkg/cache"
"github.com/elastic/fleet-server/v7/internal/pkg/config"
"github.com/rs/zerolog"
"go.elastic.co/apm/v2"
)

const (
Expand Down Expand Up @@ -51,11 +52,8 @@ func (pt *PGPRetrieverT) handlePGPKey(zlog zerolog.Logger, w http.ResponseWriter
if r.TLS == nil {
return ErrTLSRequired
}
key, err := authAPIKey(r, pt.bulker, pt.cache)
if err != nil {
return err
}
zlog = zlog.With().Str(LogEnrollAPIKeyID, key.ID).Logger()
// auth is not required for this endpoint.
// we also do not check if an API key is present in order to avoid making a round trip.
ctx := zlog.WithContext(r.Context())

p, err := pt.getPGPKey(ctx, zlog)
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/api/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions model/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1764,8 +1764,6 @@ paths:
operationId: getPGPKey
summary: retrieve a PGP key from the fleet-server's local storage.
description: "Get a PGP key that can be used to verify agent upgrades. Key is stored on (fleet-server's) disk."
security:
- apiKey: []
parameters:
- name: major
in: path
Expand Down Expand Up @@ -1802,8 +1800,6 @@ paths:
format: binary
"400":
$ref: "#/components/responses/badRequest"
"401":
$ref: "#/components/responses/keyNotEnabled"
"500":
description: The server has an error retrieving or reading the local key.
headers:
Expand Down
8 changes: 0 additions & 8 deletions pkg/api/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions testing/e2e/api_version/client_api_current.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,8 @@ func (tester *ClientAPITester) Artifact(ctx context.Context, apiKey, id, sha2, e
tester.Require().Equal(encodedSHA, fmt.Sprintf("%x", hash[:]))
}

func (tester *ClientAPITester) GetPGPKey(ctx context.Context, apiKey string) []byte {
client, err := api.NewClientWithResponses(tester.endpoint, api.WithHTTPClient(tester.Client), api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
req.Header.Set("Authorization", "ApiKey "+apiKey)
return nil
}))
func (tester *ClientAPITester) GetPGPKey(ctx context.Context) []byte {
client, err := api.NewClientWithResponses(tester.endpoint, api.WithHTTPClient(tester.Client))
tester.Require().NoError(err)

resp, err := client.GetPGPKeyWithResponse(ctx, 1, 2, 3, nil)
Expand Down Expand Up @@ -398,7 +395,7 @@ func (tester *ClientAPITester) TestArtifact() {
func (tester *ClientAPITester) TestGetPGPKey() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tester.GetPGPKey(ctx, tester.enrollmentKey)
tester.GetPGPKey(ctx)
}

func (tester *ClientAPITester) TestEnrollAuditUnenroll() {
Expand Down

0 comments on commit 4915d7c

Please sign in to comment.