Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ simplyblock-task-runner = "simplyblock_core.services.task_runners:main"
# (simplyblock_core.array); the name is the value of Cluster.array_plugin.
[project.entry-points."simplyblock.array_plugins"]
aws-ebs = "simplyblock_core.array.aws_ebs:AwsEbsPlugin"
pure-flasharray = "simplyblock_core.array.san:PureFlashArrayPlugin"
netapp-ontap = "simplyblock_core.array.san:NetAppOntapPlugin"
dell-powerstore = "simplyblock_core.array.san:DellPowerStorePlugin"
dell-powermax = "simplyblock_core.array.san:DellPowerMaxPlugin"
dell-powerflex = "simplyblock_core.array.san:DellPowerFlexPlugin"
hpe-wsapi = "simplyblock_core.array.san:HpeWsapiPlugin"
hpe-nimble = "simplyblock_core.array.san:HpeNimblePlugin"
ibm-flashsystem = "simplyblock_core.array.san:IbmFlashSystemPlugin"
hitachi-vsp = "simplyblock_core.array.san:HitachiVspPlugin"
huawei-dorado = "simplyblock_core.array.san:HuaweiDoradoPlugin"
infinidat-infinibox = "simplyblock_core.array.san:InfinidatInfiniBoxPlugin"

[dependency-groups]
test = [
Expand Down
9 changes: 8 additions & 1 deletion simplyblock_cli/cli-reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,8 @@ commands:
usage: >
simplyblock creates, multi-attaches, grows, fences and deletes the LUNs of a multi-attach cluster through
the array plugin registered here. The plugin is loaded and connected with the credentials before anything
is saved. The credentials are stored in the cluster's KMS, never in the cluster record. With --lun-size,
is saved. The credentials are wrapped by the cluster's KMS (or stay in an external Vault KV / KMIP secret named
by --credential-ref), never stored in the clear. With --lun-size,
every node added afterwards gets a LUN of that size created and attached on the array.
arguments:
- name: "cluster_id"
Expand Down Expand Up @@ -1624,6 +1625,12 @@ commands:
aws_secret_access_key; omit to use the instance role).
dest: credentials_file
type: str
- name: "--credential-ref"
help: >
Instead of --credentials-file: a secret kept outside simplyblock, as JSON, e.g.
`{"kind": "vault-kv", "mount": "secret", "path": "arrays/pure01"}` or `{"kind": "kmip-secret", "uid": "42"}`.
dest: credential_ref
type: str
- name: "--lun-size"
help: "Size of the LUN created for each node added to the cluster, e.g. `1T`. Default: none."
dest: lun_size
Expand Down
1 change: 1 addition & 0 deletions simplyblock_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def init_cluster__set_array(self, subparser):
subcommand.add_argument('--endpoint', help='The array\'s management endpoint (for aws-ebs: an EC2 endpoint URL override, usually empty).', type=str, default='', dest='endpoint')
subcommand.add_argument('--options', help='Plugin options as a JSON object, e.g. `{"az": "us-east-1a", "iops": 6000}`.', type=str, dest='options')
subcommand.add_argument('--credentials-file', help='A JSON file with the array credentials as an object of strings (for aws-ebs: aws_access_key_id, aws_secret_access_key; omit to use the instance role).', type=str, dest='credentials_file')
subcommand.add_argument('--credential-ref', help='Instead of --credentials-file: a secret kept outside simplyblock, as JSON, e.g. `{"kind": "vault-kv", "mount": "secret", "path": "arrays/pure01"}` or `{"kind": "kmip-secret", "uid": "42"}`.', type=str, dest='credential_ref')
subcommand.add_argument('--lun-size', help='Size of the LUN created for each node added to the cluster, e.g. `1T`. Default: none.', type=size_type(), default='0', dest='lun_size')

def init_cluster__get_array(self, subparser):
Expand Down
10 changes: 9 additions & 1 deletion simplyblock_cli/clibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,17 @@ def cluster__set_array(self, sub_command, args):
raise ValueError("--credentials-file must hold a JSON object of strings")
# Wrapped at the boundary; unwrapped only by the KMS and the plugin.
credentials = {str(k): SecretStr(v) for k, v in raw.items()}
credential_ref = None
if getattr(args, "credential_ref", None):
try:
credential_ref = json.loads(args.credential_ref)
except json.JSONDecodeError as e:
raise ValueError(f"--credential-ref is not valid JSON: {e}")
if not isinstance(credential_ref, dict):
raise ValueError("--credential-ref must be a JSON object")
view = array_controller.register_array(
args.cluster_id, args.plugin, args.endpoint or "", options, credentials,
int(args.lun_size or 0))
int(args.lun_size or 0), credential_ref=credential_ref)
return _format_result([view], json=getattr(args, "json", False))

def cluster__get_array(self, sub_command, args):
Expand Down
64 changes: 58 additions & 6 deletions simplyblock_core/array/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
registry that loads a vendor plugin by name from the entry-point group
``simplyblock.array_plugins``. The array's credentials live in the KMS at
``cluster/<cluster id>/array/<array id>``; the Cluster record keeps the plugin
name, endpoint and options only. Built-in plugin: ``aws-ebs``
(:mod:`.aws_ebs`). Registration and the LUN lifecycle are in
name, endpoint and options only. Built-in plugins: ``aws-ebs``
(:mod:`.aws_ebs`) and the SAN arrays (:mod:`.san`). Registration and the LUN lifecycle are in
:mod:`simplyblock_core.controllers.array_controller`.

Plugins are found only through the entry-point group or an explicit
Expand Down Expand Up @@ -40,6 +40,18 @@
#: pyproject.toml).
BUILTIN_PLUGINS = {
"aws-ebs": "simplyblock_core.array.aws_ebs:AwsEbsPlugin",
# SAN arrays: the storage_arrays adapters (simplyblock_core.array.san).
"pure-flasharray": "simplyblock_core.array.san:PureFlashArrayPlugin",
"netapp-ontap": "simplyblock_core.array.san:NetAppOntapPlugin",
"dell-powerstore": "simplyblock_core.array.san:DellPowerStorePlugin",
"dell-powermax": "simplyblock_core.array.san:DellPowerMaxPlugin",
"dell-powerflex": "simplyblock_core.array.san:DellPowerFlexPlugin",
"hpe-wsapi": "simplyblock_core.array.san:HpeWsapiPlugin",
"hpe-nimble": "simplyblock_core.array.san:HpeNimblePlugin",
"ibm-flashsystem": "simplyblock_core.array.san:IbmFlashSystemPlugin",
"hitachi-vsp": "simplyblock_core.array.san:HitachiVspPlugin",
"huawei-dorado": "simplyblock_core.array.san:HuaweiDoradoPlugin",
"infinidat-infinibox": "simplyblock_core.array.san:InfinidatInfiniBoxPlugin",
}


Expand Down Expand Up @@ -269,17 +281,56 @@ def load_plugin(name: str, endpoint: str = "", options: dict | None = None,
return plugin


def credential_context(array_id: str, endpoint: str) -> str:
"""What an array's credentials are bound to: the array id and the
scheme/host/port of its endpoint. A credential wrapped for one array is
refused for another endpoint, so rewriting the endpoint in the database
cannot send it elsewhere."""
from urllib.parse import urlsplit
ep = (endpoint or "").strip()
parts = urlsplit(ep)
if parts.scheme and parts.hostname:
port = parts.port or (443 if parts.scheme == "https" else 80)
ep = f"{parts.scheme}://{parts.hostname.lower()}:{port}"
return f"array/{array_id}/{ep}"


def credential_ref_view(cluster) -> dict:
"""The cluster's array credential reference without anything secret:
the kind, and for an external secret where it lives."""
ref = dict(getattr(cluster, "array_credential_ref", None) or {})
if not ref:
return {}
if ref.get("kind") == "managed":
return {"kind": "managed", "backend": ref.get("backend", "")}
return {k: v for k, v in ref.items() if k in ("kind", "mount", "path", "version", "uid", "field")}


def array_credentials(cluster) -> dict:
"""The credentials of the cluster's array from the KMS (``SecretStr``
values), or ``{}`` when the array was registered without any (e.g. the
EBS plugin on the instance role) or no array is registered.
"""The credentials of the cluster's array (``SecretStr`` values), or
``{}`` when the array was registered without any (e.g. the EBS plugin on
the instance role) or no array is registered.

Read through ``Cluster.array_credential_ref`` (wrapped by the cluster's
KMS, or an external Vault KV / KMIP secret); arrays registered before
references existed are read from their KMS path.

Raises:
ArrayError: a secret is recorded but cannot be read.
"""
array_id = getattr(cluster, "array_id", "") or ""
if not array_id or getattr(cluster, "array_has_credentials", False) is not True:
return {}
ref = getattr(cluster, "array_credential_ref", None) or {}
if ref:
from simplyblock_core import credentials as creds_mod
try:
resolved = creds_mod.CredentialProvider(cluster, ttl_s=0).resolve(
ref, credential_context(array_id, getattr(cluster, "array_endpoint", "") or ""))
except creds_mod.CredentialError as e:
raise ArrayError(f"array credentials could not be read: {e}") from e
return {name: resolved.get(name) for name in resolved.field_names
if name != creds_mod.CONTEXT_FIELD}
from simplyblock_core import kms
try:
with kms.create_kms_connection(cluster) as conn:
Expand Down Expand Up @@ -319,7 +370,8 @@ def _config_key(cluster) -> tuple:
getattr(cluster, "array_endpoint", "") or "",
json.dumps(getattr(cluster, "array_options", None) or {}, sort_keys=True, default=str),
getattr(cluster, "array_id", "") or "",
getattr(cluster, "array_has_credentials", False) is True)
getattr(cluster, "array_has_credentials", False) is True,
json.dumps(getattr(cluster, "array_credential_ref", None) or {}, sort_keys=True))


def cached_plugin_for_cluster(cluster, max_age: float | None = None) -> ArrayPlugin:
Expand Down
Loading
Loading