Skip to content

Commit

Permalink
Intermediate BasicAuth implementation with sharness tests.
Browse files Browse the repository at this point in the history
Still needs:

-   Client-side credentials input via config file
-   Better-formatted response to bad credentials (server-side)
-   Go tests
  • Loading branch information
dgrisham committed Oct 4, 2017
1 parent b010c40 commit 2bf672a
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 21 deletions.
27 changes: 14 additions & 13 deletions api/restapi/restapi.go
Expand Up @@ -56,7 +56,14 @@ type RESTAPI struct {
wg sync.WaitGroup
}

// Config provide is used in the NewRESTAPI constructor to define the desired
// parameters for the RESTAPI. The only required field is apiMAddr, the rest
// of the fields are optional. Generally, if an optional field is empty
// the corresponding feature will not be used.
type Config struct {
// required
ApiMAddr ma.Multiaddr
// optional
TLS *tls.Config
BasicAuthCreds map[string]string
}
Expand All @@ -72,16 +79,10 @@ type peerAddBody struct {
PeerMultiaddr string `json:"peer_multiaddress"`
}

// NewRESTAPI creates a new REST API component. It receives
// the multiaddress on which the API listens.
func NewRESTAPI(apiMAddr ma.Multiaddr) (*RESTAPI, error) {
return NewRESTAPIWithConfig(apiMAddr, &Config{})
}

// NewRESTAPI creates a new REST API component. It receives
// the multiaddress on which the API listens.
func NewRESTAPIWithConfig(apiMAddr ma.Multiaddr, cfg *Config) (*RESTAPI, error) {
n, addr, err := manet.DialArgs(apiMAddr)
// NewRESTAPI creates a new REST API component. It receives the multiaddress on
// which the API listens and a Config object.
func NewRESTAPI(cfg *Config) (*RESTAPI, error) {
n, addr, err := manet.DialArgs(cfg.ApiMAddr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -109,7 +110,7 @@ func NewRESTAPIWithConfig(apiMAddr ma.Multiaddr, cfg *Config) (*RESTAPI, error)
api := &RESTAPI{
ctx: ctx,
cancel: cancel,
apiAddr: apiMAddr,
apiAddr: cfg.ApiMAddr,
listener: l,
server: s,
rpcReady: make(chan struct{}, 1),
Expand Down Expand Up @@ -139,7 +140,7 @@ func basicAuth(h http.HandlerFunc, credentials map[string]string) http.HandlerFu
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
username, password, ok := r.BasicAuth()
if !ok {
http.Error(w, "Not authorized", 401)
http.Error(w, "Unauthorized", 401)
return
}
authorized := false
Expand All @@ -149,7 +150,7 @@ func basicAuth(h http.HandlerFunc, credentials map[string]string) http.HandlerFu
}
}
if !authorized {
http.Error(w, "Not authorized", 401)
http.Error(w, "Unauthorized", 401)
return
}
h.ServeHTTP(w, r)
Expand Down
2 changes: 1 addition & 1 deletion api/restapi/restapi_test.go
Expand Up @@ -21,7 +21,7 @@ var (
func testRESTAPI(t *testing.T) *RESTAPI {
//logging.SetDebugLogging()
apiMAddr, _ := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/10002")
rest, err := NewRESTAPI(apiMAddr)
rest, err := NewRESTAPI(&Config{ApiMAddr: apiMAddr})
if err != nil {
t.Fatal("should be able to create a new Api: ", err)
}
Expand Down
37 changes: 36 additions & 1 deletion ipfs-cluster-ctl/main.go
Expand Up @@ -31,6 +31,8 @@ var (
defaultTimeout = 60
defaultProtocol = "http"
defaultTransport = http.DefaultTransport
defaultUsername = ""
defaultPassword = ""
)

var logger = logging.Logger("cluster-ctl")
Expand Down Expand Up @@ -89,7 +91,7 @@ func main() {
},
cli.BoolFlag{
Name: "no-check-certificate",
Usage: "do not verify server TLS certificate. only valid with `--https` flag.",
Usage: "do not verify server TLS certificate. only valid with --https flag",
},
cli.StringFlag{
Name: "encoding, enc",
Expand All @@ -105,11 +107,30 @@ func main() {
Name: "debug, d",
Usage: "set debug log level",
},
cli.StringFlag{
Name: "credentials, c",
Usage: "specify BasicAuth credentials for server that requires " +
"authorization. implies --https, you can disable this with --force-http",
EnvVar: "CLUSTER_CREDENTIALS",
},
cli.BoolFlag{
Name: "force-http, f",
Usage: "force HTTP. only valid when using BasicAuth",
},
}

app.Before = func(c *cli.Context) error {
defaultHost = c.String("host")
defaultTimeout = c.Int("timeout")
// check for BasicAuth credentials
if c.IsSet("credentials") {
defaultUsername, defaultPassword = parseCredentials(c.String("credentials"))
// turn on HTTPS unless flag says not to
if !c.Bool("force-http") {
err := c.Set("https", "true")
checkErr("setting HTTPS flag for BasicAuth (this should never fail)", err)
}
}
if c.Bool("https") {
defaultProtocol = "https"
defaultTransport = newTLSTransport(c.Bool("no-check-certificate"))
Expand Down Expand Up @@ -447,6 +468,10 @@ func request(method, path string, body io.Reader, args ...string) *http.Response
checkErr("creating request", err)
r.WithContext(ctx)

if len(defaultUsername) != 0 && len(defaultPassword) != 0 {
r.SetBasicAuth(defaultUsername, defaultPassword)
}

client := &http.Client{Transport: defaultTransport}
resp, err := client.Do(r)
checkErr(fmt.Sprintf("performing request to %s", defaultHost), err)
Expand Down Expand Up @@ -484,6 +509,16 @@ func formatResponse(c *cli.Context, r *http.Response) {
}
}

func parseCredentials(userInput string) (string, string) {
credentials := strings.SplitN(userInput, ":", 2)
if len(credentials) != 2 {
err := fmt.Errorf("invalid <username>:<password> input")
checkErr("parsing credentials", err)
return "", ""
}
return credentials[0], credentials[1]
}

// JSON output is nice and allows users to build on top.
func prettyPrint(buf []byte) {
var dst bytes.Buffer
Expand Down
4 changes: 2 additions & 2 deletions ipfs-cluster-service/main.go
Expand Up @@ -280,8 +280,8 @@ func run(c *cli.Context) error {
tlsCfg, err = newTLSConfig(cfg.SSLCertFile, cfg.SSLKeyFile)
checkErr("creating TLS config: ", err)
}
apiConfig := &restapi.Config{TLS: tlsCfg, BasicAuthCreds: cfg.BasicAuthCredentials}
api, err = restapi.NewRESTAPIWithConfig(cfg.APIAddr, apiConfig)
apiConfig := &restapi.Config{ApiMAddr: cfg.APIAddr, TLS: tlsCfg, BasicAuthCreds: cfg.BasicAuthCredentials}
api, err = restapi.NewRESTAPI(apiConfig)
checkErr("creating REST API component", err)

proxy, err := ipfshttp.NewConnector(
Expand Down
2 changes: 1 addition & 1 deletion ipfscluster_test.go
Expand Up @@ -85,7 +85,7 @@ func createComponents(t *testing.T, i int, clusterSecret []byte) (*Config, API,
cfg.ReplicationFactor = -1
cfg.MonitoringIntervalSeconds = 2

api, err := restapi.NewRESTAPI(cfg.APIAddr)
api, err := restapi.NewRESTAPI(&Config{ApiMAddr: cfg.APIAddr})
checkErr(t, err)
ipfs, err := ipfshttp.NewConnector(
cfg.IPFSNodeAddr,
Expand Down
20 changes: 20 additions & 0 deletions sharness/config/basic_auth/service.json
@@ -0,0 +1,20 @@
{
"id": "QmdEtBsfumeH2V6dnx1fgn8zuW7XYjWdgJF4NEYpEBcTsg",
"private_key": "CAASqAkwggSkAgEAAoIBAQC/ZmfWDbwyI0nJdRxgHcTdEaBFQo8sky9E+OOvtwZa5WKoLdHyHOLWxCAdpIHUBbhxz5rkMEWLwPI6ykqLIJToMPO8lJbKVzphOjv4JwpiAPdmeSiYMKLjx5V8MpqU2rwj/Uf3sRL8Gg9/Tei3PZ8cftxN1rkQQeeaOtk0CBxUFZSHEsyut1fbgIeL7TAY+4vCmXW0DBr4wh9fnoES/YivOvSiN9rScgWg6N65LfkI78hzaOJ4Nok2S4vYFCxjTAI9NWFUbhP5eJIFzTU+bZuQZxOn2qsoyw8pNZwuF+JClA/RcgBcCvVZcDH2ueVq/zT++bGCN+EWsAEdvJqJ5bsjAgMBAAECggEAaGDUZ6t94mnUJ4UyQEh7v4OJP7wYkFqEAL0qjfzl/lPyBX1XbQ3Ltwul6AR6uMGV4JszARZCFwDWGLGRDWZrTmTDxyfRQ+9l6vfzFFVWGDQmtz+Dn9uGOWnyX5TJMDxJNec+hBmRHOKpaOd37dYxGz0jr19V9UO7piRJp1J1AHUCypUGv5x1IekioSCu5fEyc7dyWwnmITHBjD08st+bCcjrIUFeXSdJKC8SymYeXdaVE3xH3zVEISKnrfT7bhuKZY1iibZIlXbVLNpyX36LkYJOiCqsMum3u70LH0VvTypkqiDbD4S6qfJ4vvUakpmKpOPutikiP7jkSP+AkaO0AQKBgQDkTuhnDK6+Y0a/HgpHJisji0coO+g2gsIszargHk8nNY2AB8t+EUn7C+Qu8cmrem5V8EXcdxS6z7iAXpJmY1Xepnsz+JP7Q91Lgt3OoqK5EybzUXXKkmNCD65n70Xxn2fEFzm6+GJP3c/HymlDKU2KBCYIyuUeaREjT0Fu3v6tgQKBgQDWnXppJwn4LJHhzFOCeO4zomDJDbLTZCabdKZoFP9r+vtEHAnclDDKx4AYbomSqgERe+DX6HR/tPHRVizP63RYPf7al2mJmPzt1nTkoc1/q5hQoD+oE154dADsW1pUp7AQjwCtys4iq5S0qAwIDpuY8M8bOHwZ+QmBvHYAigJCowKBgQC3HH6TX/2rH463bE2MARXqXSPGJj45sigwrQfW1xhe9zm1LQtN4mn2mvP5nt1D1l82OA6gIzYSGtX8x10eF5/ggqAf78goZ6bOkHh76b8fNzgvQO97eGt5qYAVRjhP8azU/lfEGMEpE1s5/6LrRe41utwSg0C+YkBnlIKDfQDAgQKBgDoBTCF5hK9H1JHzuKpt5uubuo78ndWWnvyrNYKyEirsJddNwLiWcO2NqChyT8qNGkbQdX/Fex89F5KduPTlTYfAEc6g18xxxgK+UM+uj60vArbf6PSTb5gculcnha2VuPdwvx050Cb8uu9s7/uJfzKB+2f/B0O51ID1H+ubYWsDAoGBAKrwGKHyqFTHSPg3XuRA1FgDAoOsfzP9ZJvMEXUWyu/VxjNt+0mRlyGeZ5qb9UZG+K/In4FbC/ux2P/PucCUIbgy/XGPtPXVavMwNbx0MquAcU0FihKXP0CUpi8zwiYc42MF7n/SztQnismxigBMSuJEDurcXXazjfcSRTypduNn",
"cluster_secret": "84399cd0be811c2ca372d6ca473ffd73c09034f991c5e306fe9ada6c5fcfb641",
"cluster_peers": [],
"bootstrap": [],
"leave_on_shutdown": false,
"cluster_multiaddress": "/ip4/0.0.0.0/tcp/9096",
"api_listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
"basic_auth_credentials": {
"testuser": "testpass"
},
"ipfs_proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
"ipfs_node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
"state_sync_seconds": 60,
"ipfs_sync_seconds": 130,
"replication_factor": -1,
"monitoring_interval_seconds": 15,
"allocation_strategy": "reposize"
}
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions sharness/config/ssl-basic_auth/service.json
@@ -0,0 +1,20 @@
{
"id": "QmdEtBsfumeH2V6dnx1fgn8zuW7XYjWdgJF4NEYpEBcTsg",
"private_key": "CAASqAkwggSkAgEAAoIBAQC/ZmfWDbwyI0nJdRxgHcTdEaBFQo8sky9E+OOvtwZa5WKoLdHyHOLWxCAdpIHUBbhxz5rkMEWLwPI6ykqLIJToMPO8lJbKVzphOjv4JwpiAPdmeSiYMKLjx5V8MpqU2rwj/Uf3sRL8Gg9/Tei3PZ8cftxN1rkQQeeaOtk0CBxUFZSHEsyut1fbgIeL7TAY+4vCmXW0DBr4wh9fnoES/YivOvSiN9rScgWg6N65LfkI78hzaOJ4Nok2S4vYFCxjTAI9NWFUbhP5eJIFzTU+bZuQZxOn2qsoyw8pNZwuF+JClA/RcgBcCvVZcDH2ueVq/zT++bGCN+EWsAEdvJqJ5bsjAgMBAAECggEAaGDUZ6t94mnUJ4UyQEh7v4OJP7wYkFqEAL0qjfzl/lPyBX1XbQ3Ltwul6AR6uMGV4JszARZCFwDWGLGRDWZrTmTDxyfRQ+9l6vfzFFVWGDQmtz+Dn9uGOWnyX5TJMDxJNec+hBmRHOKpaOd37dYxGz0jr19V9UO7piRJp1J1AHUCypUGv5x1IekioSCu5fEyc7dyWwnmITHBjD08st+bCcjrIUFeXSdJKC8SymYeXdaVE3xH3zVEISKnrfT7bhuKZY1iibZIlXbVLNpyX36LkYJOiCqsMum3u70LH0VvTypkqiDbD4S6qfJ4vvUakpmKpOPutikiP7jkSP+AkaO0AQKBgQDkTuhnDK6+Y0a/HgpHJisji0coO+g2gsIszargHk8nNY2AB8t+EUn7C+Qu8cmrem5V8EXcdxS6z7iAXpJmY1Xepnsz+JP7Q91Lgt3OoqK5EybzUXXKkmNCD65n70Xxn2fEFzm6+GJP3c/HymlDKU2KBCYIyuUeaREjT0Fu3v6tgQKBgQDWnXppJwn4LJHhzFOCeO4zomDJDbLTZCabdKZoFP9r+vtEHAnclDDKx4AYbomSqgERe+DX6HR/tPHRVizP63RYPf7al2mJmPzt1nTkoc1/q5hQoD+oE154dADsW1pUp7AQjwCtys4iq5S0qAwIDpuY8M8bOHwZ+QmBvHYAigJCowKBgQC3HH6TX/2rH463bE2MARXqXSPGJj45sigwrQfW1xhe9zm1LQtN4mn2mvP5nt1D1l82OA6gIzYSGtX8x10eF5/ggqAf78goZ6bOkHh76b8fNzgvQO97eGt5qYAVRjhP8azU/lfEGMEpE1s5/6LrRe41utwSg0C+YkBnlIKDfQDAgQKBgDoBTCF5hK9H1JHzuKpt5uubuo78ndWWnvyrNYKyEirsJddNwLiWcO2NqChyT8qNGkbQdX/Fex89F5KduPTlTYfAEc6g18xxxgK+UM+uj60vArbf6PSTb5gculcnha2VuPdwvx050Cb8uu9s7/uJfzKB+2f/B0O51ID1H+ubYWsDAoGBAKrwGKHyqFTHSPg3XuRA1FgDAoOsfzP9ZJvMEXUWyu/VxjNt+0mRlyGeZ5qb9UZG+K/In4FbC/ux2P/PucCUIbgy/XGPtPXVavMwNbx0MquAcU0FihKXP0CUpi8zwiYc42MF7n/SztQnismxigBMSuJEDurcXXazjfcSRTypduNn",
"cluster_secret": "84399cd0be811c2ca372d6ca473ffd73c09034f991c5e306fe9ada6c5fcfb641",
"cluster_peers": [],
"bootstrap": [],
"leave_on_shutdown": false,
"cluster_multiaddress": "/ip4/0.0.0.0/tcp/9096",
"api_listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
"ssl_cert_file": "test-config/server.crt",
"ssl_key_file": "test-config/server.key",
"basic_auth_credentials": { "testuser" : "testpass" },
"ipfs_proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
"ipfs_node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
"state_sync_seconds": 60,
"ipfs_sync_seconds": 130,
"replication_factor": -1,
"monitoring_interval_seconds": 15,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wYD
VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAIxqpKYzF6A9RlLso0lkF
nYfcyeVAvi03IBdiTNnpOe6ROa4gNwKH/JUJMCRDPzm/x78+srCmrcCCAJJTcqgi
b84vq3DegGPg2NXbn9qVUA1SdiXFelqMFwLitDn2KKizihEN4L5PEArHuDaNvLI+
kMr+yZSALWTdtfydj211c7hTBvFqO8l5MYDXCmfoS9sqniorlNHIaBim/SNfDsi6
8hAhvfRvk3e6dPjAPrIZYdQR5ROGewtD4F/anXgKY2BmBtWwd6gbGeMnnVi1SGRP
0UHc4O9aq9HrAOFL/72WVk/kyyPyJ/GtSaPYL1OFS12R/l0hNi+pER7xDtLOVHO2
iw==
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions sharness/config/ssl/server.key
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAu6g/w96EYi2Yo+Lf7xIhXWrPwLcWIrzlf8g3FguPK7O+mYNE
62WQ692Y8Imu94oNkXsQJCnAgYCkVucoIJbfN049CYBXObg3xu+fMW0z2ZObyopv
1LBGLpktn+pej3y3wLsJXoVo0pSQjDSVR6xmJcRyaSeuU/Ley9oNBWhI4fwvfx3S
DiB6qI2syZkNoZ7wUBh2kKh5gMib+7QCD3Ibf5cBsRPFaGR9PIfddxD8jODTAb3M
VjzL9/JjAL4Lv7EXvnHiBsjMcBjaIVLa5rsZMprYZmE5e0y7Mnpx/5NlbjrRn474
+QDVofTVasYvuIJb/oKf2A9Eov4g/qLIOeH0cwIDAQABAoIBAAOYreArG45mIU7C
wlfqmQkZSvH+kEYKKLvSMnwRrKTBxR1cDq4UPDrI/G1ftiK4Wpo3KZAH3NCejoe7
1mEJgy2kKjdMZl+M0ETXws1Hsn6w/YNcM9h3qGCsPtuZukY1ta/T5dIR7HhcsIh/
WX0OKMcAhNDPGeAx/2MYwrcf0IXELx0+eP1fuBllkajH14J8+ZkVrBMDhqppn8Iq
f9po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harness/lib/test-lib.sh
Expand Up @@ -96,6 +96,6 @@ test_clean_ipfs(){

test_clean_cluster(){
kill -1 "$CLUSTER_D_PID"
rm -rf test-config
rm -rf 'test-config'
sleep 2
}
2 changes: 1 addition & 1 deletion sharness/t0040-ssl-simple-exchange.sh
Expand Up @@ -2,7 +2,7 @@

test_description="Test service + ctl SSL interaction"

ssl_config="`pwd`/ssl"
ssl_config="`pwd`/config/ssl"

. lib/test-lib.sh

Expand Down
1 change: 0 additions & 1 deletion sharness/t0041-ssl-enforcement.sh
Expand Up @@ -14,7 +14,6 @@ test_expect_success "prerequisites" '
'

test_expect_success "ssl enforced by client" '
test_cluster_config
id=`cluster_id`
test_must_fail ipfs-cluster-ctl --https --no-check-certificate id
'
Expand Down
41 changes: 41 additions & 0 deletions sharness/t0042-basic-auth.sh
@@ -0,0 +1,41 @@
#!/bin/sh

test_description="Test service + ctl SSL interaction"

config="`pwd`/config/basic_auth"

. lib/test-lib.sh

test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init "$config"
cleanup test_clean_cluster

test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq CLUSTER
'

test_expect_success "BasicAuth fails without credentials" '
id=`cluster_id`
test_must_fail ipfs-cluster-ctl id
'

test_expect_success "BasicAuth fails with bad credentials" '
id=`cluster_id`
test_must_fail ipfs-cluster-ctl -c "testuser:badpass" --force-http id
test_must_fail ipfs-cluster-ctl -c "baduser:testpass" --force-http id
test_must_fail ipfs-cluster-ctl -c "baduser:badpass" --force-http id
'

test_expect_success "BasicAuth over HTTP succeeds with CLI flag credentials" '
id=`cluster_id`
ipfs-cluster-ctl -c "testuser:testpass" --force-http id | egrep -q "$id"
'

test_expect_success "ssl interaction succeeds with env var credentials" '
id=`cluster_id`
export CLUSTER_CREDENTIALS="testuser:testpass"
ipfs-cluster-ctl --force-http id | egrep -q "$id"
'

test_done
23 changes: 23 additions & 0 deletions sharness/t0043-ssl-basic-auth.sh
@@ -0,0 +1,23 @@
#!/bin/sh

test_description="Test service + ctl SSL interaction"

config="`pwd`/config/ssl-basic_auth"

. lib/test-lib.sh

test_ipfs_init
cleanup test_clean_ipfs
test_cluster_init "$config"
cleanup test_clean_cluster

test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq CLUSTER
'

test_expect_success "ssl interaction succeeds" '
id=`cluster_id`
ipfs-cluster-ctl --no-check-certificate -c "testuser:testpass" id | egrep -q "$id"
'

test_done

0 comments on commit 2bf672a

Please sign in to comment.