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

Feature 02 instance principal #3

Open
wants to merge 34 commits into
base: feature-01-profile
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
11cbb44
Impliments OCI Instance Principal
damithkothalawala May 4, 2024
e6d3f53
Adding validate_options to stop people getting confused.
damithkothalawala May 4, 2024
a6e8ac0
Update Documentation
damithkothalawala May 4, 2024
70a4348
Update Documentation
damithkothalawala May 4, 2024
da4d14d
Bump version
damithkothalawala May 4, 2024
fcb7215
Update Documentation. Bug Fix
damithkothalawala May 4, 2024
5d7f75e
Update Documentation. Bug Fix
damithkothalawala May 4, 2024
9267aeb
Update Documentation. Bug Fix
damithkothalawala May 4, 2024
8bfa78f
Bug Fix
damithkothalawala May 4, 2024
1c092ed
Bug Fix
damithkothalawala May 4, 2024
b509ec1
Bug Fix
damithkothalawala May 4, 2024
fee3360
Bug Fix
damithkothalawala May 4, 2024
8ed2c7a
Bug Fix
damithkothalawala May 4, 2024
f212fad
Bug Fix
damithkothalawala May 4, 2024
8cde5d3
Bug Fix
damithkothalawala May 4, 2024
9d4a750
Bug Fix
damithkothalawala May 4, 2024
dd6e2d9
Bug Fix
damithkothalawala May 4, 2024
ca2d73f
Bug Fix
damithkothalawala May 4, 2024
44f2c7a
Bug Fix
damithkothalawala May 4, 2024
2749ef7
Bug Fix
damithkothalawala May 4, 2024
e471bc7
Bug Fix
damithkothalawala May 4, 2024
9b3d31f
Bug Fix
damithkothalawala May 4, 2024
5f678df
Bug Fix
damithkothalawala May 4, 2024
2b77da8
Bug Fix
damithkothalawala May 4, 2024
6997427
Increase Propagation to 60s
damithkothalawala May 4, 2024
47ae105
Update Documentation
damithkothalawala May 4, 2024
8c7eb42
Bug Fix
damithkothalawala May 4, 2024
c6928b4
Bug Fix
damithkothalawala May 4, 2024
96f5b25
Bug Fix
damithkothalawala May 4, 2024
775c4da
Bug Fix
damithkothalawala May 4, 2024
5426e7d
Bug Fix
damithkothalawala May 4, 2024
a21d387
Bug Fix
damithkothalawala May 4, 2024
b333d70
Bug Fix: There is a problem with oci_config credentils
damithkothalawala May 4, 2024
0a0f9c4
Trying to Fix Consturct Error
damithkothalawala May 4, 2024
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
23 changes: 22 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ To use this authenticator you will need:
* a registered domain name, configured with the OCI DNS servers
* that domain name created in OCI (via the console, the CLI, or the API)
* an OCI account with adequate permission to Create / Update / Delete DNS entries in that domain
* or instance principal setup on the target instance with the same permissions

Installation
------------
Expand Down Expand Up @@ -75,7 +76,10 @@ This plug-in supports the following arguments on certbot's command line:

``--dns-oci-propagation-seconds`` Amount of time to allow for the DNS change to propagate
before asking the ACME server to verify the DNS record.
(Default: 15)
(Default: 60)

``--dns-oci-instance-principal`` Use instance principal for authentication.
(Optional) set this to 'y' to use instance principal
======================================= ========================================================


Expand All @@ -91,6 +95,15 @@ To acquire a TEST certificate for demosite.ociateam.com:
--authenticator dns-oci -d demosite.ociateam.com


To acquire a TEST certificate for demosite.ociateam.com using instance principal:

.. code-block:: bash

certbot --test-cert certonly \
--logs-dir logs --work-dir work --dns-oci-instance-principal=y \
--authenticator dns-oci -d demosite.ociateam.com


To acquire a *real* certificate for demosite.ociateam.com:

.. code-block:: bash
Expand All @@ -99,3 +112,11 @@ To acquire a *real* certificate for demosite.ociateam.com:
--logs-dir logs --work-dir work --config-dir config \
--authenticator dns-oci -d demosite.ociateam.com


To acquire a *real* certificate for demosite.ociateam.com using instance principal:

.. code-block:: bash

certbot certonly \
--logs-dir logs --work-dir work --dns-oci-instance-principal=y \
--authenticator dns-oci -d demosite.ociateam.com
53 changes: 39 additions & 14 deletions certbot_dns_oci/dns_oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ def __init__(self, *args, **kwargs):
# self.credentials = None

@classmethod
def add_parser_arguments(cls, add, **kwargs): # pylint: disable=arguments-differ
def add_parser_arguments(cls, add): # pylint: disable=arguments-differ
super(Authenticator, cls).add_parser_arguments(
add, default_propagation_seconds=15
add, default_propagation_seconds=60
)
# TODO: implement these:
add('config', help="OCI CLI Configuration file.")
add('profile', help="OCI configuration profile (in OCI configuration file)")
# Add argument for instance principal
add('instance-principal',help="Use instance principal for authentication.")

def validate_options(self):
# Validate options to ensure that conflicting arguments are not provided together
if self.conf('instance-principal') and self.conf('config'):
raise errors.PluginError(
"Conflicting arguments: '--dns-oci-instance-principal' and '--dns-oci-config' cannot be provided together."
)

def more_info(self): # pylint: disable=missing-docstring,no-self-use
return (
Expand All @@ -39,11 +48,17 @@ def more_info(self): # pylint: disable=missing-docstring,no-self-use
)

def _setup_credentials(self):
# implement profile - full implementation of config file is WIP
oci_config_profile = 'DEFAULT'
if self.conf('profile') is not None:
oci_config_profile = self.conf('profile')
self.credentials = oci.config.from_file(profile_name=oci_config_profile)
# Validate options
self.validate_options()

if self.conf('instance-principal') is None:
self.credentials = oci.config.from_file()

oci_config_profile = 'DEFAULT'
if self.conf('profile') is not None:
oci_config_profile = self.conf('profile')
self.credentials = oci.config.from_file(profile_name=oci_config_profile)


def _perform(self, domain, validation_name, validation):
self._get_ocidns_client().add_txt_record(
Expand All @@ -56,7 +71,10 @@ def _cleanup(self, domain, validation_name, validation):
)

def _get_ocidns_client(self):
return _OCIDNSClient(self.credentials)
if self.conf('instance-principal') is not None:
return _OCIDNSClient(None)
else:
return _OCIDNSClient(self.credentials)


class _OCIDNSClient:
Expand All @@ -67,11 +85,18 @@ class _OCIDNSClient:
In Other Words: thar be dragons
"""

def __init__(self, oci_config):
logger.debug("creating OCI DnsClient")
# this is where you would add code to handle Resource, Instance, or non-default configs
config = oci.config.from_file()
self.dns_client = oci.dns.DnsClient(oci_config)
def __init__(self, oci_config=None):
if oci_config is not None:
logger.debug("creating OCI DnsClient Using Config File")
# this is where you would add code to handle Resource, Instance, or non-default configs
config = oci.config.from_file()
self.dns_client = oci.dns.DnsClient(oci_config)
else:
logger.debug("creating OCI DnsClient Using Instance Principal")
# this is where you would add code to handle Resource, Instance, or non-default configs
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
self.dns_client = oci.dns.DnsClient(config={}, signer=signer)


def add_txt_record(self, domain, record_name, record_content, record_ttl):
"""
Expand All @@ -89,7 +114,7 @@ def add_txt_record(self, domain, record_name, record_content, record_ttl):
# first find the domain
zone_ocid, zone_name = self._find_managed_zone(domain, record_name)
if zone_name is None:
raise errors.PluginError("Domain not known")
raise errors.PluginError("Domain not known. Please Make sure the domain is in OCI DNS and You have the correct permissions.")
logger.debug("Found domain %s with OCID %s", zone_name, zone_ocid)

# NOTE: the OCI SDK will treat:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup
from setuptools import find_packages

version = "0.1.0"
version = "0.1.1"

install_requires = [
"acme>=1.31.0",
Expand Down