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

rpk: use redpanda.admin if rpk.admin_api is nil #6955

Merged

Conversation

r-vasquez
Copy link
Contributor

@r-vasquez r-vasquez commented Oct 26, 2022

Cover letter

Previously rpk will use rpk.admin_api.addresses to communicate with admin API, if that field isn't set, rpk will use the default 127.0.0.1:9644

That's a problem if we are running in non-default port or address, now, rpk will use redpanda.admin if rpk.admin_api.addresses is not set

Fixes #2752, Fixes #6860

Backport Required

  • papercut/not impactful enough to backport
  • v22.2.x
  • v22.1.x
  • v21.11.x

UX changes

Let's say you have this config file:

redpanda:
    ...
    admin:
        - address: 1.2.3.4   # non-default address
          port: 9645            # non-default port
    developer_mode:  true
    auto_create_topics_enabled: true
    group_topic_partitions: 3
    storage_min_free_bytes: 10485760
    topic_partitions_per_shard: 1000
rpk:
    tune_disk_irq: true
    ... # no rpk.admin_api set.

Running rpk cluster health will give you an error like this::

* unable to fetch metrics from the admin API: Get "http://127.0.0.1:9644/...

The above happened because rpk will use the default host:port instead of using the one set in redpanda.admin property, now, rpk will use redpanda.admin (1.2.3.4:9645) in this same scenario.

Release notes

Improvements

  • rpk now will use admin address from redpanda.admin in the redpanda.yaml file if rpk.admin_api.addresses is empty.
  • rpk will now use broker addresses from redpanda.kafka_api in the redpanda.yaml file if rpk.kafka_api.brokers is empty

twmb
twmb previously approved these changes Oct 26, 2022
defer func() { r.AdminAPI.Addresses = addrs }()
if len(addrs) == 0 && len(c.Redpanda.AdminAPI) > 0 {
for _, adminAPI := range c.Redpanda.AdminAPI {
addrs = append(addrs, net.JoinHostPort(adminAPI.Address, strconv.Itoa(adminAPI.Port)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably have a preference about what listener to use.

The admin API can have mTLS on a per-listener basis: if someone has configured an insecure listener on 127.0.0.1, then that is probably the one that rpk wants to use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to go this route, we can use https://pkg.go.dev/net#IP.IsPrivate and sort that one first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/go/rpk/pkg/config/params.go Outdated Show resolved Hide resolved
@r-vasquez
Copy link
Contributor Author

Force Push:

  • Sort admin API addresses
  • Unit test for this method

@r-vasquez r-vasquez force-pushed the discover-admin-api-in-redpanda branch 2 times, most recently from 8d6c0f3 to 250cd13 Compare October 26, 2022 20:19
@r-vasquez r-vasquez requested review from jcsp and twmb October 26, 2022 20:20
if len(addrs) == 0 && len(c.Redpanda.AdminAPI) > 0 {
// We want to order the admin API addresses by:
// localhost -> loobpack -> private -> public.
var localhost, loopback, private, public []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address order looks right, I would recommend also ordering non-mTLS endpoints first

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed -- non-TLS is sorted first, and if we see any non-TLS, we avoid TLS listeners entirely

jcsp
jcsp previously approved these changes Oct 27, 2022
Copy link
Contributor

@jcsp jcsp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks like there is a go linter complaining though

@twmb twmb force-pushed the discover-admin-api-in-redpanda branch 2 times, most recently from b8e99b9 to f551082 Compare October 27, 2022 21:39
r-vasquez and others added 2 commits October 27, 2022 15:41
Previously rpk will use rpk.admin_api.addresses
to communicate with admin API, if that field
isn't set, rpk will use the default 127.0.0.1:9644

That's a problem if we are running in non-default
port or address, now, rpk will use
redpanda.admin _if_ rpk.admin_api.addresses is
not set
jcsp
jcsp previously approved these changes Oct 28, 2022
The prior commits introduce behavior to use redpanda.admin if
rpk.admin_api is empty. We previously had this same behavior for
rpk.kafka_api, but this only used redpanda.kafka_api[0]. We abstract the
logic from the previous commit (and have a authn => no authn helper) to
make using the prior commit just as simple for brokers.

We also do *not* use TLS listeners if we have any non-TLS listeners: rpk
likely cannot fill client certs, and they may not be on the host. The
expected behavior is that a person ssh's into the node and then runs
rpk; localhost non-TLS communication will work.

The new abstraction is well setup for when we add support for pandaproxy
and schemaregistry to rpk, both of which use the same types.

This adds testing for all this behavior as well.
Improving on the prior commit, we also now prefer tls over mtls. *If* we
have to use tls, we are more likely able to communicate with brokers
that do not require client certs (because we cannot setup client certs).
admin api's PrometheusMetrics actually requires one host to send to
(i.e. you must pick the one host you want metrics from). Our tests
previously passed because rpk.admin_api was empty and then we used the
default 127.0.0.1:9644. The tests now failed because redpanda.admin was
non-empty and we picked all three brokers in it. Because we favor the
most-likely-accessible host first, we can just pick the first host in
the config.
See embedded comment. A server listening on 0.0.0.0 is not an IP we can
dial, but it does result in us being able to dial 127.0.0.1.
@twmb
Copy link
Contributor

twmb commented Oct 28, 2022

Failure: #6745

@piyushredpanda piyushredpanda merged commit 5d51cc6 into redpanda-data:dev Oct 28, 2022
@r-vasquez r-vasquez deleted the discover-admin-api-in-redpanda branch November 9, 2022 18:44
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants