1Password/solutions

replace-http-with-https.sh fails to replace website URLs when using a Service Account with access to multiple vaults

jbsoliman opened this issue · 1 comments

Problem

Service accounts require a --vault flag if it has access to more than one vault. As a result, unexpected issues occur when attempting to use replace-http-with-https.sh.

Expected behavior

The "http" in the "website" field within a 1Password login item is replaced with "https".

Actual Behavior

[ERROR] <date> <time> a vault query must be provided when this command is called by a service account. Please specify one either through the --vault flag or through piped input

"website" value for all relevant items are erased:
CleanShot 2023-08-30 at 10 21 02

Environment

CLI 2.20
Ubuntu 20.04.2 ARM64

Suggestion

Add a '--vault' flag to each op item call in the script:

#!/usr/bin/env bash
#########################################################
# REPLACE HTTP WITH HTTPS 
#########################################################
# This script will replace "http" with "https" for the 
# website field of all Login items in the specified vault 

#Provide a vault UUID or vault name
vaultUUID=""

# add new url to each item
for item in $(op item list --vault $vaultUUID --categories Login --format json | jq --raw-output '.[].id')
do
	oldURL=$(op item get $item --vault $vaultUUID --format=json | jq --raw-output '.urls[].href')
	newURL=$(echo $oldURL | sed 's/^http:\/\//https:\/\//g')
	op item edit $item --vault $vaultUUID website=$newURL
done

Nice catch. Service accounts wasn't a use-case I had thought of but should definitely be accommodated. Fix incoming!