Skip to content

Commit

Permalink
Merge branch 'v3' into vulnerability-scan
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 authored Jul 12, 2024
2 parents c0bfc32 + 50693ac commit c631cd1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
19 changes: 10 additions & 9 deletions cmd/jimmctl/cmd/controllerinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ var (
controller-info command writes controller information contained
in the juju client store to a yaml file.
If a --local flag is specified, the output controller
public address will use the first available local API address
and the local CA cert of the controller, see examples below
for usage.
If a public address is specified, the output controller information
will contain the public address provided and omit a CA cert, this assumes
that the server is secured with a public certificate.
Use the --local flag if the server is not configured with a public cert.
See examples below for usage.
Examples:
jimmctl controller-info <name> <filename> <public address>
Expand Down Expand Up @@ -85,6 +88,9 @@ func (c *controllerInfoCommand) Init(args []string) error {
if c.local && len(c.publicAddress) > 0 {
return errors.New("cannot set both public address and local flag")
}
if !c.local && len(c.publicAddress) == 0 {
return errors.New("provide either a public address or use --local")
}
return nil
}

Expand All @@ -111,13 +117,8 @@ func (c *controllerInfoCommand) Run(ctxt *cmd.Context) error {
info.TLSHostname = c.tlsHostname
info.PublicAddress = c.publicAddress
if c.local {
info.PublicAddress = controller.APIEndpoints[0]
info.CACertificate = controller.CACert
}
if info.PublicAddress == "" {
return errors.New("public address must be set")
}

data, err := yaml.Marshal(info)
if err != nil {
return errors.Mask(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/jimmctl/cmd/controllerinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *controllerInfoSuite) TestControllerInfoMissingPublicAddressAndNoLocalFl
fname := path.Join(dir, "test.yaml")

_, err = cmdtesting.RunCommand(c, cmd.NewControllerInfoCommandForTesting(store), "controller-1", fname)
c.Assert(err, gc.ErrorMatches, "public address must be set")
c.Assert(err, gc.ErrorMatches, "provide either a public address or use --local")
}

func (s *controllerInfoSuite) TestControllerInfoCannotProvideAddrAndLocalFlag(c *gc.C) {
Expand Down
1 change: 0 additions & 1 deletion internal/jujuclient/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (d *Dialer) Dial(ctx context.Context, ctl *dbmodel.Controller, modelTag nam
facades[fmt.Sprintf("%s\x1f%d", fv.Name, v)] = true
}
}
zapctx.Error(ctx, "facades", zap.Any("version", bestFacadeVersions))

monitorC := make(chan struct{})
broken := new(uint32)
Expand Down
21 changes: 18 additions & 3 deletions internal/rpc/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"

"github.com/gorilla/websocket"
"github.com/juju/juju/core/network"
"github.com/juju/names/v5"
"github.com/juju/zaputil"
"github.com/juju/zaputil/zapctx"
Expand Down Expand Up @@ -84,10 +85,9 @@ func Dial(ctx context.Context, ctl *dbmodel.Controller, modelTag names.ModelTag,
var urls []string
for _, hps := range ctl.Addresses {
for _, hp := range hps {
if hp.Scope != "public" && hp.Scope != "" {
continue
if maybeReachable(hp.Scope) {
urls = append(urls, websocketURL(fmt.Sprintf("%s:%d", hp.Value, hp.Port), modelTag, finalPath))
}
urls = append(urls, websocketURL(fmt.Sprintf("%s:%d", hp.Value, hp.Port), modelTag, finalPath))
}
}
zapctx.Debug(ctx, "Dialling all URLs", zap.Any("urls", urls))
Expand All @@ -98,6 +98,21 @@ func Dial(ctx context.Context, ctl *dbmodel.Controller, modelTag names.ModelTag,
return conn, nil
}

// maybeReachable decides what kinds of links JIMM should try to connect via.
// Local IPs like localhost for example are excluded but public IPs and Cloud local IPs are potentially reachable.
func maybeReachable(scope string) bool {
switch scope {
case string(network.ScopeCloudLocal):
return true
case string(network.ScopePublic):
return true
case "":
return true
default:
return false
}
}

func websocketURL(s string, mt names.ModelTag, finalPath string) string {
u := url.URL{
Scheme: "wss",
Expand Down
2 changes: 1 addition & 1 deletion local/jimm/add-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ echo "Switching juju controller to $JIMM_CONTROLLER_NAME"
juju switch "$JIMM_CONTROLLER_NAME"
echo
echo "Retrieving controller info for $CONTROLLER_NAME"
./jimmctl controller-info --local "$CONTROLLER_NAME" "$CONTROLLER_YAML_PATH"
./jimmctl controller-info --local "$CONTROLLER_NAME" "$CONTROLLER_YAML_PATH" --tls-hostname juju-apiserver
if [[ -f "$CONTROLLER_YAML_PATH" ]]; then
echo "Controller info retrieved."
else
Expand Down

0 comments on commit c631cd1

Please sign in to comment.