Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenStack Infrastructure as Code Automation
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cloud
g2-openstack
OpenStack Infrastructure as Code Automation
Commits
9d71635a
Commit
9d71635a
authored
1 year ago
by
František Řezníček
Browse files
Options
Downloads
Patches
Plain Diff
feat: extract information about VM and volumes/SGes
parent
f81bd38e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
clouds/g1/brno/security_incidents/identify_cloud_resources.sh
+96
-0
96 additions, 0 deletions
...ds/g1/brno/security_incidents/identify_cloud_resources.sh
with
96 additions
and
0 deletions
clouds/g1/brno/security_incidents/identify_cloud_resources.sh
0 → 100755
+
96
−
0
View file @
9d71635a
#!/bin/bash
#
# identify_cloud_resources.sh -h|--help
# dumps this help
#
# identify_cloud_resources.sh -i|--fip <ip-address>
# identifies cloud resources from the associated floating IP address
# identify_cloud_resources.sh -s|--server <server-name-or-id>
# identifies cloud resources from the openstack server name/ID
#
# This script identifies what cloud resources are necessary to dump
#
# Example executions:
# Find information about VM using FIP 147.251.124.228
# * SSH_ARGS="-i $HOME/.ssh/id_rsa.LenovoThinkCentreE73" ./identify_cloud_resources.sh --fip 147.251.124.228
#
set
-eo
pipefail
SSH_ARGS
=
${
SSH_ARGS
:-
""
}
function
usage
()
{
local
file
=
"
$1
"
awk
'{if(NR>1){if($1 ~ /^#(.+|$)/){print substr($0,3)}else{exit(0)}}}'
$file
}
PARGS
=
$(
getopt
-o
"h,s:,i:"
-l
"help,server:,fip:"
-n
"
$0
"
--
"
$@
"
)
eval set
--
"
$PARGS
"
HELP
=
0
SERVER
=
""
FIP
=
""
while
[
"
$1
"
!=
"--"
]
;
do
case
"
$1
"
in
-h
|
--help
)
usage
"
$0
"
exit
0
;;
-i
|
--fip
)
FIP
=
"
$2
"
shift
2
;;
-s
|
--server
)
SERVER
=
"
$2
"
shift
2
;;
esac
done
if
[
-z
"
${
FIP
}
"
-a
-z
"
${
SERVER
}
"
]
;
then
usage
"
$0
"
exit
1
fi
echo
"Connecting to OpenStack cloud:"
openstack version show
-fcsv
|
grep
identity
if
[
-n
"
${
FIP
}
"
]
;
then
echo
"Translate FIP to VM:"
fip_json
=
"
$(
openstack floating ip show
"
${
FIP
}
"
-fjson
)
"
port_id
=
$(
echo
"
${
fip_json
}
"
| jq
-r
'.port_id'
)
echo
" * port ID:
${
port_id
}
"
port_json
=
"
$(
openstack port show
"
${
port_id
}
"
-fjson
)
"
SERVER
=
$(
echo
"
${
port_json
}
"
| jq
-r
'.device_id'
)
echo
" * server ID:
${
SERVER
}
"
fi
server_json
=
"
$(
openstack server show
"
${
SERVER
}
"
-fjson
)
"
echo
"OpenStack server details:"
server_id
=
"
$(
echo
"
${
server_json
}
"
| jq
-r
'.id'
)
"
echo
"* ID:
${
server_id
}
"
echo
"* name:
$(
echo
"
${
server_json
}
"
| jq
-r
'.name'
)
"
echo
"* project:"
project_id
=
"
$(
echo
"
${
server_json
}
"
| jq
-r
'.project_id'
)
"
echo
"* * ID:
${
project_id
}
"
project_json
=
"
$(
openstack project show
"
${
project_id
}
"
-fjson
)
"
echo
"* * name:
$(
echo
"
${
project_json
}
"
| jq
-r
'.name'
)
"
echo
"* volumes:
$(
echo
"
${
server_json
}
"
| jq
-rc
'.volumes_attached'
)
"
hypervisor_hostname
=
"
$(
echo
"
${
server_json
}
"
| jq
-rc
'."OS-EXT-SRV-ATTR:host"'
)
"
echo
"* hypervisor:
${
hypervisor_hostname
}
"
echo
"* libvirt-domain-name:
$(
echo
"
${
server_json
}
"
| jq
-rc
'."OS-EXT-SRV-ATTR:instance_name"'
)
"
echo
"* security-groups:
$(
echo
"
${
server_json
}
"
| jq
-rc
'.security_groups'
)
"
security_group_names
=
$(
echo
"
${
server_json
}
"
| jq
-r
'.security_groups[] | .name'
)
security_groups_json
=
$(
openstack security group list
--project
${
project_id
}
-fjson
)
for
i_sg_name
in
${
security_group_names
}
;
do
i_sg_id
=
"
$(
echo
"
${
security_groups_json
}
"
| jq
-r
".[] | select(.Name ==
\"
${
i_sg_name
}
\"
) | .ID"
)
"
echo
"* * security-group
${
i_sg_name
}
(ID:
${
i_sg_id
}
)"
openstack security group show
${
i_sg_id
}
-fyaml
|
grep
-Ev
'null|tags:|tenant_id:|revision_number:|security_group_id:| id:|project_id:'
done
if
ssh
${
SSH_ARGS
}
"root@
${
hypervisor_hostname
}
"
"uname -a"
>
/dev/null
;
then
echo
"List libvirt domain block devices:"
ssh
${
SSH_ARGS
}
"root@
${
hypervisor_hostname
}
"
"virsh domblklist
${
server_id
}
"
else
echo
"Libvirt domain block device list is not available."
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment