Skip to content

Commit

Permalink
refactor(auth): Refactor RC auth
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteFoy committed Jan 18, 2023
1 parent 65b823f commit 3e81db5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
10 changes: 2 additions & 8 deletions cmd/trace-agent/remote_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"sync"
"time"

"google.golang.org/grpc/metadata"

"github.com/DataDog/datadog-agent/pkg/config/remote"
"github.com/DataDog/datadog-agent/pkg/proto/pbgo"
"github.com/DataDog/datadog-agent/pkg/trace/api"
Expand All @@ -42,7 +40,7 @@ func putBuffer(buffer *bytes.Buffer) {
bufferPool.Put(buffer)
}

func remoteConfigHandler(r *api.HTTPReceiver, client remote.ConfigUpdater, token string, cfg *config.AgentConfig) http.Handler {
func remoteConfigHandler(r *api.HTTPReceiver, client remote.ConfigUpdater, cfg *config.AgentConfig) http.Handler {
cidProvider := api.NewIDProvider(cfg.ContainerProcRoot)
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
defer timing.Since("datadog.trace_agent.receiver.config_process_ms", time.Now())
Expand All @@ -67,10 +65,6 @@ func remoteConfigHandler(r *api.HTTPReceiver, client remote.ConfigUpdater, token
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
md := metadata.MD{
"authorization": []string{fmt.Sprintf("Bearer %s", token)},
}
ctx := metadata.NewOutgoingContext(req.Context(), md)
if configsRequest.GetClient().GetClientTracer() != nil {
normalize(&configsRequest)
if configsRequest.Client.ClientTracer.Tags == nil {
Expand All @@ -80,7 +74,7 @@ func remoteConfigHandler(r *api.HTTPReceiver, client remote.ConfigUpdater, token
configsRequest.Client.ClientTracer.Tags = append(configsRequest.Client.ClientTracer.Tags, tag)
}
}
cfg, err := client.ClientGetConfigs(ctx, &configsRequest)
cfg, err := client.ClientGetConfigs(req.Context(), &configsRequest)
if err != nil {
statusCode = http.StatusInternalServerError
http.Error(w, err.Error(), statusCode)
Expand Down
8 changes: 2 additions & 6 deletions cmd/trace-agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
cmdconfig "github.com/DataDog/datadog-agent/cmd/trace-agent/config"
"github.com/DataDog/datadog-agent/cmd/trace-agent/internal/flags"
"github.com/DataDog/datadog-agent/cmd/trace-agent/internal/osutil"
"github.com/DataDog/datadog-agent/pkg/api/security"
coreconfig "github.com/DataDog/datadog-agent/pkg/config"
rc "github.com/DataDog/datadog-agent/pkg/config/remote"
"github.com/DataDog/datadog-agent/pkg/pidfile"
Expand Down Expand Up @@ -188,17 +187,14 @@ func Run(ctx context.Context) {
}()

if coreconfig.Datadog.GetBool("remote_configuration.enabled") {
// Auth tokens are handled by the rcClient
rcClient, err := rc.NewAgentGRPCConfigFetcher()
if err != nil {
osutil.Exitf("could not instantiate the tracer remote config client: %v", err)
}
token, err := security.FetchAuthToken()
if err != nil {
osutil.Exitf("could obtain the auth token for the tracer remote config client: %v", err)
}
api.AttachEndpoint(api.Endpoint{
Pattern: "/v0.7/config",
Handler: func(r *api.HTTPReceiver) http.Handler { return remoteConfigHandler(r, rcClient, token, cfg) },
Handler: func(r *api.HTTPReceiver) http.Handler { return remoteConfigHandler(r, rcClient, cfg) },
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (g *agentGRPCConfigFetcher) ClientGetConfigs(ctx context.Context, request *

ctx = metadata.NewOutgoingContext(ctx, md)

return g.client.ClientGetConfigs(ctx, request, opts)
return g.client.ClientGetConfigs(ctx, request, opts...)
}

// NewClient creates a new client
Expand Down

0 comments on commit 3e81db5

Please sign in to comment.