Skip to contentSkip to conversation

ndctl, test: handle backup_keys in security.sh

PATCH In review Alison Schofield 3 participants 7 messages Jun 12, 2019 – Jun 13, 2019 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 ndctl, test: handle backup_keys in security.sh

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm-master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit test")
---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/security.sh +2 -2
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 
 	if [ -f "$masterpath" ]; then
 		mv "$masterpath" "$masterpath.bak"
-		$backup_key=1
+		backup_key=1
 	fi
 	if [ -f "$keypath/tpm.handle" ]; then
 		mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-		$backup_handle=1
+		backup_handle=1
 	fi
 
 	dd if=/dev/urandom bs=1 count=32 2>/dev/null | keyctl padd user "$masterkey" @u
Signature · 6 lines
2.21.0

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#1 lore raw
Quoted 12 lines · Alison Schofield

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm- master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Quoted 6 lines
Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit

test")

---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Looks good, I'll pick it up for v66 and push it out to pending shortly.

Quoted 19 lines
test/security.sh +2 -2
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 
 	if [ -f "$masterpath" ]; then
 		mv "$masterpath" "$masterpath.bak"
-		$backup_key=1
+		backup_key=1
 	fi
 	if [ -f "$keypath/tpm.handle" ]; then
 		mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-		$backup_handle=1
+		backup_handle=1
 	fi
 
 	dd if=/dev/urandom bs=1 count=32 2>/dev/null | keyctl padd user
Quoted 1 line

"$masterkey" @u

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reviewed-by on v1 1/1
#2 lore raw
In reply to Alison Schofield
Quoted 24 lines · Alison Schofield

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm-master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit test")
---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/security.sh +0 -0
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 

test/security.sh setup_keys() · line 44

Quoted 10 lines
test/security.sh +2 -2
        if [ -f "$masterpath" ]; then
                mv "$masterpath" "$masterpath.bak"
-               $backup_key=1
+               backup_key=1
        fi
        if [ -f "$keypath/tpm.handle" ]; then
                mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-               $backup_handle=1
+               backup_handle=1
        fi

Looks obviously correct to me.

...but that said, why is this test even bothering with the host's configuration? I think it should be using a test local directory that does not disturb the rest of the system, especially because the test is using nfit_test resources.

There's no guarantee that the script successfully reaches the post_cleanup() phase to restore the host configuration and could leave it broken. Unless / until we can fix up this test to not touch /etc I think it should be moved to the ENABLE_DESTRUCTIVE set of tests.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#3 lore raw
Quoted 45 lines · Dan Williams
Quoted 23 lines · Alison Schofield

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm-master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit test")
---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/security.sh +0 -0
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 

test/security.sh setup_keys() · line 44

Quoted 10 lines
test/security.sh +2 -2
        if [ -f "$masterpath" ]; then
                mv "$masterpath" "$masterpath.bak"
-               $backup_key=1
+               backup_key=1
        fi
        if [ -f "$keypath/tpm.handle" ]; then
                mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-               $backup_handle=1
+               backup_handle=1
        fi

Looks obviously correct to me.

...but that said, why is this test even bothering with the host's configuration? I think it should be using a test local directory that does not disturb the rest of the system, especially because the test is using nfit_test resources.

Quoted 4 lines

There's no guarantee that the script successfully reaches the post_cleanup() phase to restore the host configuration and could leave it broken. Unless / until we can fix up this test to not touch /etc I think it should be moved to the ENABLE_DESTRUCTIVE set of tests.

Hm, yes good point. I agree with moving it to destructive for now.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#4 lore raw
Quoted 40 lines · Vishal L
Quoted 38 lines · Dan Williams
Quoted 23 lines · Alison Schofield

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm-master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit test")
---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/security.sh +0 -0
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 

test/security.sh setup_keys() · line 44

Quoted 10 lines
test/security.sh +2 -2
        if [ -f "$masterpath" ]; then
                mv "$masterpath" "$masterpath.bak"
-               $backup_key=1
+               backup_key=1
        fi
        if [ -f "$keypath/tpm.handle" ]; then
                mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-               $backup_handle=1
+               backup_handle=1
        fi

Looks obviously correct to me.

Quoted 6 lines
Quoted 6 lines

...but that said, why is this test even bothering with the host's configuration? I think it should be using a test local directory that does not disturb the rest of the system, especially because the test is using nfit_test resources.

At first glance, it appears that the keys need to be in the {ndctl_keysdir}, aka, the official system location, for some of the ndctl commands to run. So, it's not as simple as just creating the key blob in a temp directory.

And, I don't even think that's the nfit_test resource you are referring to anyway. I'll keep a look out for how it can run cleaner, and make it off the ENABLE_DESTRUCTIVE list in the future.

Quoted 7 lines
Quoted 5 lines

There's no guarantee that the script successfully reaches the post_cleanup() phase to restore the host configuration and could leave it broken. Unless / until we can fix up this test to not touch /etc I think it should be moved to the ENABLE_DESTRUCTIVE set of tests.

Hm, yes good point. I agree with moving it to destructive for now.

Vishal, Do you need a patch that moves it to the naughty list?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#5 lore raw
Quoted 47 lines · Alison Schofield
Quoted 39 lines · Vishal L
Quoted 38 lines · Dan Williams
Quoted 23 lines · Alison Schofield

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm-master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit test")
---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/security.sh +0 -0
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 

test/security.sh setup_keys() · line 44

Quoted 10 lines
test/security.sh +2 -2
        if [ -f "$masterpath" ]; then
                mv "$masterpath" "$masterpath.bak"
-               $backup_key=1
+               backup_key=1
        fi
        if [ -f "$keypath/tpm.handle" ]; then
                mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-               $backup_handle=1
+               backup_handle=1
        fi

Looks obviously correct to me.

Quoted 6 lines
Quoted 6 lines

...but that said, why is this test even bothering with the host's configuration? I think it should be using a test local directory that does not disturb the rest of the system, especially because the test is using nfit_test resources.

Quoted 8 lines

At first glance, it appears that the keys need to be in the {ndctl_keysdir}, aka, the official system location, for some of the ndctl commands to run. So, it's not as simple as just creating the key blob in a temp directory.

And, I don't even think that's the nfit_test resource you are referring to anyway. I'll keep a look out for how it can run cleaner, and make it off the ENABLE_DESTRUCTIVE list in the future.

Yes I think eventually we want the keys to be configurable on a more fine-grained bases, and that would allow for other locations.

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

There's no guarantee that the script successfully reaches the post_cleanup() phase to restore the host configuration and could leave it broken. Unless / until we can fix up this test to not touch /etc I think it should be moved to the ENABLE_DESTRUCTIVE set of tests.

Hm, yes good point. I agree with moving it to destructive for now.

Vishal, Do you need a patch that moves it to the naughty list?

I wouldn't say no to one!

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#6 lore raw
In reply to Alison Schofield
Quoted 49 lines · Alison Schofield
Quoted 40 lines · Vishal L
Quoted 38 lines · Dan Williams
Quoted 23 lines · Alison Schofield

Fix a typo in security.sh that causes a script failure when an nvdimm-master.blob already exists and needs to be backed up.

+ setup_keys
+ '[' '!' -d /etc/ndctl/keys ']'
+ '[' -f /etc/ndctl/keys/nvdimm-master.blob ']'
+ mv /etc/ndctl/keys/nvdimm-master.blob /etc/ndctl/keys/nvdimm-master.blob.bak
+ 0=1
./security.sh: line 39: 0=1: command not found

Fixes ba35642d3815 ("ndctl: add a load-keys test in the security unit test")
---
 test/security.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/security.sh +0 -0
index 8a36265..c86d2c6 100755
@@ -36,11 +36,11 @@ setup_keys()
 

test/security.sh setup_keys() · line 44

Quoted 10 lines
test/security.sh +2 -2
        if [ -f "$masterpath" ]; then
                mv "$masterpath" "$masterpath.bak"
-               $backup_key=1
+               backup_key=1
        fi
        if [ -f "$keypath/tpm.handle" ]; then
                mv "$keypath/tpm.handle" "$keypath/tmp.handle.bak"
-               $backup_handle=1
+               backup_handle=1
        fi

Looks obviously correct to me.

Quoted 6 lines
Quoted 6 lines

...but that said, why is this test even bothering with the host's configuration? I think it should be using a test local directory that does not disturb the rest of the system, especially because the test is using nfit_test resources.

Quoted 4 lines

At first glance, it appears that the keys need to be in the {ndctl_keysdir}, aka, the official system location, for some of the ndctl commands to run. So, it's not as simple as just creating the key blob in a temp directory.

Currently, yes, but the typical way to override a build time configuration is with an environment variable, similar to what we do with NDCTL_TIMEOUT.

Quoted 3 lines

And, I don't even think that's the nfit_test resource you are referring to anyway. I'll keep a look out for how it can run cleaner, and make it off the ENABLE_DESTRUCTIVE list in the future.

The test uses fake DIMMs from $NFIT_TEST_BUS0.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm