Repository: fabric-testbed/fabrictestbed-extensions (language: python)

Issue:
Ensure slice key and bastion key names are not identical
- Ensure slice key and bastion key names are not identical
- While checking expiry for bastion keys on compare against bastion keys


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 31c4ba50..b305e2d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## Unreleased
 
-
+### Fixed
+- Ensure slice key and bastion key names are not identical (Issue [#389](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/389))
 
 ## [1.7.4] - 11/05/2024 
 


Test patch:
diff --git a/fabrictestbed_extensions/fablib/constants.py b/fabrictestbed_extensions/fablib/constants.py
index 6f5e9649..a6f9ef7b 100644
--- a/fabrictestbed_extensions/fablib/constants.py
+++ b/fabrictestbed_extensions/fablib/constants.py
@@ -166,6 +166,7 @@ class Constants:
     SSH_KEYS = "sshkeys"
     EXPIRES_ON = "expires_on"
     LEASE_TIME_FORMAT = "%Y-%m-%d %H:%M:%S %z"
+    FABRIC_KEY_TYPE = "fabric_key_type"
 
     NON_PRETTY_NAME = "non_pretty_name"
     PRETTY_NAME = "pretty_name"
diff --git a/fabrictestbed_extensions/fablib/fablib.py b/fabrictestbed_extensions/fablib/fablib.py
index 9c1b0017..35d12b6d 100644
--- a/fabrictestbed_extensions/fablib/fablib.py
+++ b/fabrictestbed_extensions/fablib/fablib.py
@@ -837,6 +837,19 @@ def verify_and_configure(self):
         Utils.is_reachable(hostname=self.get_core_api_host(), port=443)
         Utils.is_reachable(hostname=self.get_bastion_host(), port=22)
 
+        if (
+            self.get_default_slice_private_key_file() is not None
+            and self.get_bastion_key_location() is not None
+            and self.get_default_slice_private_key_file()
+            == self.get_bastion_key_location()
+        ):
+            logging.error(
+                "Sliver Key and Bastion key can not be same! Please use different key names!"
+            )
+            raise Exception(
+                "Sliver Key and Bastion key can not be same! Please use different key names!"
+            )
+
         self.validate_and_update_bastion_keys()
 
         if (
@@ -949,6 +962,10 @@ def validate_and_update_bastion_keys(self):
             if now > expires_on_dt:
                 keys_to_remove.append(key)
                 continue
+            key_type = key.get(Constants.FABRIC_KEY_TYPE)
+            if key_type and key_type != Constants.KEY_TYPE_BASTION:
+                keys_to_remove.append(key)
+                continue
 
         for key in keys_to_remove:
             ssh_keys.remove(key)