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

Allow the agent to connect to a secure grpc endpoint #116

Merged
merged 1 commit into from
May 19, 2020
Merged
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
10 changes: 9 additions & 1 deletion cmd/drone-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package main

import (
"context"
"crypto/tls"
"encoding/json"
grpccredentials "google.golang.org/grpc/credentials"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -83,9 +85,15 @@ func loop(c *cli.Context) error {

// grpc.Dial(target, ))

var transport = grpc.WithInsecure()

if c.Bool("secure-grpc") {
transport = grpc.WithTransportCredentials(grpccredentials.NewTLS(&tls.Config{InsecureSkipVerify: c.Bool("skip-insecure-grpc")}))
}

conn, err := grpc.Dial(
c.String("server"),
grpc.WithInsecure(),
transport,
grpc.WithPerRPCCredentials(&credentials{
username: c.String("username"),
password: c.String("password"),
Expand Down
10 changes: 10 additions & 0 deletions cmd/drone-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func main() {
Usage: "after pinging for a keepalive check, the agent waits for a duration of this time before closing the connection if no activity",
Value: time.Second * 20,
},
cli.BoolFlag{
Name: "secure-grpc",
Usage: "should the connection to DRONE_SERVER be made using a secure transport",
EnvVar: "DRONE_GRPC_SECURE",
},
cli.BoolTFlag{
Name: "skip-insecure-grpc",
Usage: "should the grpc server certificate be verified, only valid when DRONE_GRPC_SECURE is true",
EnvVar: "DRONE_GRPC_VERIFY",
},
}

if err := app.Run(os.Args); err != nil {
Expand Down