Skip to content

Commit

Permalink
Update pkidestroy to support ACME
Browse files Browse the repository at this point in the history
pkidestroy has been updated to support removing ACME from
PKI server. If it is the last subsystem on the server, the
server will be removed as well.

The ACMESubsystem.create() has been modified to create a base
dir (i.e. /var/lib/pki/<instance>/<subsystem>) which is used
by PKIServer.load_subsystems() to determine if the subsystem
exists. The code that creates the conf and logs folders has
been moved into create_conf() and create_logs(), respectively.

The pki-server acme-remove has been updated to provide new
options to remove the conf and logs folders.

The tests that use pkispawn to install ACME have been updated
to use pkidestroy to remove ACME.
  • Loading branch information
edewata committed Sep 20, 2024
1 parent 1b7fd92 commit dbbb876
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 22 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/acme-basic-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxrwx--- pkiuser pkiuser acme
lrwxrwxrwx pkiuser pkiuser alias -> /var/lib/pki/pki-tomcat/conf/alias
lrwxrwxrwx pkiuser pkiuser bin -> /usr/share/tomcat/bin
drwxrwx--- pkiuser pkiuser ca
Expand Down Expand Up @@ -175,7 +176,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxr-xr-x pkiuser pkiuser acme
drwxrwx--- pkiuser pkiuser acme
drwxr-x--- pkiuser pkiuser backup
drwxrwx--- pkiuser pkiuser ca
-rw-rw-r-- pkiuser pkiuser catalina.$DATE.log
Expand All @@ -188,6 +189,23 @@ jobs:
diff expected output
- name: Check ACME base dir
if: always()
run: |
docker exec pki ls -l /var/lib/pki/pki-tomcat/acme \
| sed \
-e '/^total/d' \
-e 's/^\(\S*\) *\S* *\(\S*\) *\(\S*\) *\S* *\S* *\S* *\S* *\(.*\)$/\1 \2 \3 \4/' \
| tee output
# TODO: review permissions
cat > expected << EOF
lrwxrwxrwx pkiuser pkiuser conf -> /var/lib/pki/pki-tomcat/conf/acme
lrwxrwxrwx pkiuser pkiuser logs -> /var/lib/pki/pki-tomcat/logs/acme
EOF
diff expected output
- name: Check ACME conf dir
run: |
# check file types, owners, and permissions
Expand Down Expand Up @@ -221,6 +239,11 @@ jobs:
run: |
docker exec pki cat /etc/pki/pki-tomcat/acme/realm.conf
- name: Check ACME logs dir
if: always()
run: |
docker exec pki ls -l /var/log/pki/pki-tomcat/acme
- name: Check initial ACME accounts
run: |
docker exec ds ldapsearch \
Expand Down Expand Up @@ -664,9 +687,7 @@ jobs:
diff expected actual
- name: Remove ACME from PKI container
run: |
docker exec pki pki-server acme-undeploy --wait
docker exec pki pki-server acme-remove
run: docker exec pki pkidestroy -s ACME -v

- name: Remove CA from PKI container
run: docker exec pki pkidestroy -s CA -v
Expand Down Expand Up @@ -700,6 +721,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxrwx--- pkiuser pkiuser Catalina
drwxrwx--- pkiuser pkiuser acme
drwxrwx--- pkiuser pkiuser alias
drwxrwx--- pkiuser pkiuser ca
-rw-r--r-- pkiuser pkiuser catalina.policy
Expand Down Expand Up @@ -729,7 +751,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxr-xr-x pkiuser pkiuser acme
drwxrwx--- pkiuser pkiuser acme
drwxr-x--- pkiuser pkiuser backup
drwxrwx--- pkiuser pkiuser ca
-rw-rw-r-- pkiuser pkiuser catalina.$DATE.log
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/acme-postgresql-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ jobs:
diff expected actual
- name: Remove ACME from PKI container
run: |
docker exec pki pki-server acme-undeploy --wait
docker exec pki pki-server acme-remove
run: docker exec pki pkidestroy -s ACME -v

- name: Remove CA from PKI container
run: docker exec pki pkidestroy -s CA -v
Expand Down
35 changes: 28 additions & 7 deletions .github/workflows/acme-separate-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxrwx--- pkiuser pkiuser acme
lrwxrwxrwx pkiuser pkiuser alias -> /var/lib/pki/pki-tomcat/conf/alias
lrwxrwxrwx pkiuser pkiuser bin -> /usr/share/tomcat/bin
drwxr-x--- pkiuser pkiuser common
Expand Down Expand Up @@ -231,6 +232,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxrwx--- pkiuser pkiuser acme
drwxr-x--- pkiuser pkiuser backup
-rw-r--r-- pkiuser pkiuser catalina.$DATE.log
-rw-r--r-- pkiuser pkiuser host-manager.$DATE.log
Expand All @@ -240,6 +242,23 @@ jobs:
diff expected output
- name: Check ACME base dir
if: always()
run: |
docker exec acme ls -l /var/lib/pki/pki-tomcat/acme \
| sed \
-e '/^total/d' \
-e 's/^\(\S*\) *\S* *\(\S*\) *\(\S*\) *\S* *\S* *\S* *\S* *\(.*\)$/\1 \2 \3 \4/' \
| tee output
# TODO: review permissions
cat > expected << EOF
lrwxrwxrwx pkiuser pkiuser conf -> /var/lib/pki/pki-tomcat/conf/acme
lrwxrwxrwx pkiuser pkiuser logs -> /var/lib/pki/pki-tomcat/logs/acme
EOF
diff expected output
- name: Check ACME conf dir
run: |
# check file types, owners, and permissions
Expand Down Expand Up @@ -273,6 +292,11 @@ jobs:
run: |
docker exec acme cat /etc/pki/pki-tomcat/acme/realm.conf
- name: Check ACME logs dir
if: always()
run: |
docker exec acme ls -l /var/log/pki/pki-tomcat/acme
- name: Check initial ACME accounts
run: |
docker exec acmeds ldapsearch \
Expand Down Expand Up @@ -724,14 +748,10 @@ jobs:
diff expected actual
- name: Remove ACME
run: |
docker exec acme pki-server acme-undeploy --wait -v
docker exec acme pki-server acme-remove -v
docker exec acme pki-server stop --wait -v
docker exec acme pki-server remove -v
run: docker exec acme pkidestroy -s ACME -v

- name: Remove CA
run: docker exec ca pkidestroy -i pki-tomcat -s CA -v
run: docker exec ca pkidestroy -s CA -v

- name: Check ACME server base dir after removal
run: |
Expand Down Expand Up @@ -762,6 +782,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxr-x--- pkiuser pkiuser Catalina
drwxrwx--- pkiuser pkiuser acme
drwxrwx--- pkiuser pkiuser alias
-rw-rw---- pkiuser pkiuser catalina.policy
lrwxrwxrwx pkiuser pkiuser catalina.properties -> /usr/share/pki/server/conf/catalina.properties
Expand Down Expand Up @@ -789,7 +810,7 @@ jobs:
# TODO: review permissions
cat > expected << EOF
drwxr-xr-x pkiuser pkiuser acme
drwxrwx--- pkiuser pkiuser acme
drwxr-x--- pkiuser pkiuser backup
-rw-r--r-- pkiuser pkiuser catalina.$DATE.log
-rw-r--r-- pkiuser pkiuser host-manager.$DATE.log
Expand Down
2 changes: 1 addition & 1 deletion base/server/python/pki/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
ETC_SYSTEMD_DIR = '/etc/systemd'
LIB_SYSTEMD_DIR = '/lib/systemd'

SUBSYSTEM_TYPES = ['ca', 'kra', 'ocsp', 'tks', 'tps']
SUBSYSTEM_TYPES = ['ca', 'kra', 'ocsp', 'tks', 'tps', 'acme']

DEFAULT_DIR_MODE = 0o0770
DEFAULT_FILE_MODE = 0o0660
Expand Down
27 changes: 22 additions & 5 deletions base/server/python/pki/server/cli/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def execute(self, argv):

subsystem = pki.server.subsystem.ACMESubsystem(instance)
subsystem.create(force=force)
subsystem.create_conf(force=force)
subsystem.create_logs(force=force)


class ACMERemoveCLI(pki.cli.CLI):
Expand All @@ -111,6 +113,8 @@ def print_help(self):
print('Usage: pki-server acme-remove [OPTIONS] [name]')
print()
print(' -i, --instance <instance ID> Instance ID (default: pki-tomcat).')
print(' --remove-conf Remove config folder.')
print(' --remove-logs Remove logs folder.')
print(' --force Force removal.')
print(' -v, --verbose Run in verbose mode.')
print(' --debug Run in debug mode.')
Expand All @@ -122,22 +126,29 @@ def execute(self, argv):
try:
opts, args = getopt.gnu_getopt(argv, 'i:v', [
'instance=',
'force',
'remove-conf', 'remove-logs', 'force',
'verbose', 'debug', 'help'])

except getopt.GetoptError as e:
logger.error(e)
self.print_help()
sys.exit(1)

name = 'acme'
instance_name = 'pki-tomcat'
remove_conf = False
remove_logs = False
force = False

for o, a in opts:
if o in ('-i', '--instance'):
instance_name = a

elif o == '--remove-conf':
remove_conf = True

elif o == '--remove-logs':
remove_logs = True

elif o == '--force':
force = True

Expand Down Expand Up @@ -166,9 +177,15 @@ def execute(self, argv):

instance.load()

acme_conf_dir = os.path.join(instance.conf_dir, name)
logger.info('Removing %s', acme_conf_dir)
pki.util.rmtree(acme_conf_dir, force=force)
subsystem = pki.server.subsystem.ACMESubsystem(instance)

if remove_logs:
subsystem.remove_logs(force=force)

if remove_conf:
subsystem.remove_conf(force=force)

subsystem.remove(force=force)


class ACMEDeployCLI(pki.cli.CLI):
Expand Down
49 changes: 49 additions & 0 deletions base/server/python/pki/server/deployment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5187,6 +5187,8 @@ def create_acme_subsystem(self):

subsystem = pki.server.subsystem.ACMESubsystem(self.instance)
subsystem.create()
subsystem.create_conf()
subsystem.create_logs()

return subsystem

Expand Down Expand Up @@ -5371,6 +5373,49 @@ def spawn_acme(self):

self.deploy_acme_webapp(subsystem)

def undeploy_acme_webapp(self, subsystem):
'''
See also pki-server acme-undeploy.
'''

logger.info('Undeploying ACME webapp')

subsystem.disable(wait=True)

def remove_acme_subsystem(self, subsystem):
'''
See also pki-server acme-remove.
'''

logger.info('Removing ACME subsystem')

if self.remove_logs:
subsystem.remove_logs(force=self.force)

if self.remove_conf:
subsystem.remove_conf(force=self.force)

subsystem.remove(force=self.force)

def destroy_acme(self):

subsystem = self.instance.remove_subsystem('acme')

self.undeploy_acme_webapp(subsystem)
self.remove_acme_subsystem(subsystem)

if len(self.instance.get_subsystems()) == 0:
# if this is the last subsystem, stop the server
self.instance.stop(
wait=True,
max_wait=self.startup_timeout,
timeout=self.request_timeout)

# then remove the server
self.instance.remove(
remove_conf=self.remove_conf,
remove_logs=self.remove_logs)

def create_est_subsystem(self):
'''
See also pki-server est-create.
Expand Down Expand Up @@ -5564,6 +5609,10 @@ def destroy(self):

print('Uninstalling ' + self.subsystem_type + ' from ' + self.instance.base_dir + '.')

if self.subsystem_type == 'ACME':
self.destroy_acme()
return

scriptlet = pki.server.deployment.scriptlets.initialization.PkiScriptlet()
scriptlet.deployer = self
scriptlet.instance = self.instance
Expand Down
Loading

0 comments on commit dbbb876

Please sign in to comment.