Skip to content

metadata_url config does not respect Juju proxy settings #248

Description

@hk21702

Bug Description

Presntly, the metadata_url config does not respect Juju proxy settings, meaning that we can't use this feature to fetch metadata information via a proxy.

Impact

Medium (functionality degraded, workaround exists)

Impact Rationale

The issue effectively means that we can't use metadata_url with an egress filtered environment. We can get around it by fetching the metadata ourselves and configuring using metadata to achieve similar functionality, but it isn't great.

This impacts K8s environments more than VM environments since we could probably just attach AProxy to the integrator charm in a VM environment.

To Reproduce

  1. Ensure Juju model proxy settings are correct and allows egress to the desired location
  2. Deploy saml-integrator-operator in a egress filtered environment
  3. Configure metadata_url
  4. Observe reachability errors

Environment

Prodstack JAAS K8s cluster.

latest/edge version of saml-integrator, revision 166.

Relevant log output

unit-saml-integrator-0: 09:59:28 ERROR unit.saml-integrator/0.juju-log saml:29: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "/usr/lib/python3.10/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/usr/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/usr/lib/python3.10/http/client.py", line 1448, in connect
    super().connect()
  File "/usr/lib/python3.10/http/client.py", line 942, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/usr/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/charm_state.py", line 106, in metadata
    with urllib.request.urlopen(  # noqa: S310
  File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.10/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/usr/lib/python3.10/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/usr/lib/python3.10/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 101] Network is unreachable>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/charm.py", line 87, in <module>
    main(SamlIntegratorOperatorCharm)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/main.py", line 39, in main
    return _main.main(charm_class=charm_class, use_juju_for_storage=use_juju_for_storage)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/_main.py", line 507, in main
    manager.run()
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/_main.py", line 491, in run
    self._emit()
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/_main.py", line 426, in _emit
    self._emit_charm_event(self.dispatcher.event_name)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/_main.py", line 470, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/framework.py", line 337, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/framework.py", line 910, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/venv/lib/python3.10/site-packages/ops/framework.py", line 1028, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/charm.py", line 48, in _on_relation_created
    self._update_relations()
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/charm.py", line 70, in _update_relations
    self.saml.update_relation_data(relation, self.get_saml_data())
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/charm.py", line 81, in get_saml_data
    certificates=self._saml_integrator.certificates,
  File "/usr/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/saml.py", line 129, in certificates
    tree = self.tree
  File "/usr/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/saml.py", line 79, in tree
    tree = self._read_tree()
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/saml.py", line 55, in _read_tree
    return etree.fromstring(self._charm_state.metadata)  # nosec
  File "/var/lib/juju/agents/unit-saml-integrator-0/charm/src/charm_state.py", line 111, in metadata
    raise CharmConfigInvalidError(
charm_state.CharmConfigInvalidError: Error while retrieving data from https://login.ubuntu.com/saml/metadata
unit-saml-integrator-0: 09:59:29 ERROR juju.worker.uniter.operation hook "saml-relation-created" (via hook dispatching script: dispatch) failed: exit status 1

Additional context

There appears to be an old PR (#14) which implemented proxy support for the charm, but it ended up being closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions