Artifactory: Difference between revisions
Jump to navigation
Jump to search
| (2 intermediate revisions by the same user not shown) | |||
| Line 99: | Line 99: | ||
jf access-token-create | jf access-token-create | ||
jf atc | jf atc | ||
Refresh tokens are commonly UUID-like strings | |||
eg. f1782ce5-5683-444d-8c17-1f62bdace278 | |||
Access tokens typically start with: | |||
eyJ... | |||
Reference tokens often start with something resembling: | |||
cmVm... | |||
Create a token that expires in 90 days: | Create a token that expires in 90 days: | ||
jf atc --expiry=7776000 --description="CLI token" | jf atc --expiry=7776000 --description="CLI token" | ||
Create a | 90 days * 24 hours per day * 60 minutes per hour * 60 seconds per minute = 7776000 seconds | ||
jf atc --expiry= | Create a token that expires in 180 days: | ||
jf atc --expiry=15552000 --description="CLI token" | |||
180 days * 24 hours per day * 60 minutes per hour * 60 seconds per minute = 15552000 seconds | |||
Create a refreshable token: | |||
jf atc --refreshable=true | |||
jf atc --refreshable | |||
Return a reference token as well: | Return a reference token as well: | ||
jf atc --reference=true | jf atc --reference=true | ||
jf atc --reference | |||
Create a 90 day refreshable token with short reference token: | |||
jf atc --expiry=7776000 --description="CLI token" --refreshable --reference | |||
Example: | |||
<pre> | |||
{ | |||
"scope": "applied-permissions/user", | |||
"access_token": "eyJ....xxx_REALLY_REALLY_LONG_TOKEN_xxx", | |||
"expires_in": 7776000, | |||
"token_type": "Bearer", | |||
"refresh_token": "59372fb0-xxxx-xxxx-xxxx-xxxxxxxxxxxx", | |||
"reference_token": "cmVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | |||
"token_id": "f28a7682-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | |||
} | |||
</pre> | |||
Refresh refreshable access token: | |||
<pre> | |||
ACCESS_TOKEN="access_token content" | |||
REFRESH_TOKEN="refresh_token content" | |||
curl -v \ | |||
-X POST \ | |||
"https://artifactory.example.com/access/api/v1/tokens" \ | |||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \ | |||
-H "Content-Type: application/x-www-form-urlencoded" \ | |||
-d "grant_type=refresh_token" \ | |||
-d "refresh_token=${REFRESH_TOKEN}" | |||
</pre> | |||
If you want to include a reference token: | |||
-d "include_reference_token=true" \ | |||
<pre> | |||
curl -v \ | |||
-X POST \ | |||
"https://artifactory.example.com/access/api/v1/tokens" \ | |||
-H "Authorization: Bearer ${ACCESS_TOKEN}" \ | |||
-H "Content-Type: application/x-www-form-urlencoded" \ | |||
-d "grant_type=refresh_token" \ | |||
-d "include_reference_token=true" \ | |||
-d "refresh_token=${REFRESH_TOKEN}" | |||
</pre> | |||
Decode the expiration date: (expiration = creation_time + expires_in) | |||
<pre> | |||
TOKEN="eyJhbGciOi..." | |||
python3 -c ' | |||
import base64,json,time | |||
t="'$TOKEN'" | |||
payload=t.split(".")[1] | |||
payload += "=" * (-len(payload) % 4) | |||
d=json.loads(base64.urlsafe_b64decode(payload)) | |||
print(json.dumps(d, indent=2)) | |||
print("Expires:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(d["exp"]))) | |||
' | |||
# or | |||
echo $TOKEN | cut -d. -f2 | base64 -d | jq . | |||
# "exp": 1787423456 | |||
</pre> | |||
Get tokens: | |||
<pre> | |||
curl \ | |||
-H "Authorization: Bearer $ACCESS_TOKEN" \ | |||
https://artifactory.example.com/access/api/v1/tokens | |||
{ | |||
"tokens" : [ { | |||
"token_id" : "961cad32-...", | |||
"subject" : "jf-access@a0a259fa-.../users/some.user@example.com", | |||
"expiry" : 1800379731, | |||
"issued_at" : 1784827731, | |||
"issuer" : "jf-access@a0a259fa-...", | |||
"description" : "CLI token", | |||
"refreshable" : true, | |||
"scope": "applied-permissions/user" | |||
}, { | |||
... | |||
} ] | |||
} | |||
NOTE: this also worked: | |||
curl -H "Authorization: Bearer $REFERENCE_TOKEN" \ | |||
https://artifactory.sandisk.com/access/api/v1/tokens | |||
</pre> | |||
== API == | == API == | ||
Latest revision as of 20:38, 23 July 2026
jfrog cli
Installation - https://jfrog.com/getcli/
Debian/Ubuntu:
# Create the keyrings directory if it doesn't exist sudo mkdir -p /usr/share/keyrings;
# Download and save the JFrog GPG key to a keyring file wget -qO - https://releases.jfrog.io/artifactory/api/v2/repositories/jfrog-debs/keyPairs/primary/public | sudo gpg --dearmor -o /usr/share/keyrings/jfrog.gpg
# Add the JFrog repository to your APT sources with the signed-by option echo "deb [signed-by=/usr/share/keyrings/jfrog.gpg] https://releases.jfrog.io/artifactory/jfrog-debs focal contrib" | sudo tee /etc/apt/sources.list.d/jfrog.list
# Update the package list sudo apt update
# Install the JFrog CLI sudo apt install -y jfrog-cli-v2-jf
# Run the JFrog CLI intro command jf intro
OLD: # wget -qO - https://releases.jfrog.io/artifactory/jfrog-gpg-public/jfrog_public_gpg.key | sudo apt-key add - # # echo "deb https://releases.jfrog.io/artifactory/jfrog-debs xenial contrib" | sudo tee -a /etc/apt/sources.list.d/jfrog.list && sudo apt update # echo "deb https://releases.jfrog.io/artifactory/jfrog-debs noble contrib" | sudo tee -a /etc/apt/sources.list.d/jfrog.list && sudo apt update # sudo apt install -y jfrog-cli-v2-jf # jf intro
Redhat:
# Create and configure the JFrog CLI YUM repository echo "[jfrog-cli]" > jfrog-cli.repo && echo "name=JFrog CLI" >> jfrog-cli.repo && echo "baseurl=https://releases.jfrog.io/artifactory/jfrog-rpms" >> jfrog-cli.repo && echo "enabled=1" >> jfrog-cli.repo && echo "gpgcheck=1" >> jfrog-cli.repo &&
# Import GPG keys for verifying packages # Note: Two keys are imported for backward compatibility with older versions rpm --import https://releases.jfrog.io/artifactory/api/v2/repositories/jfrog-rpms/keyPairs/primary/public && rpm --import https://releases.jfrog.io/artifactory/api/v2/repositories/jfrog-rpms/keyPairs/secondary/public &&
# Move the repository file to the YUM configuration directory sudo mv jfrog-cli.repo /etc/yum.repos.d/ &&
# Install the JFrog CLI package yum install -y jfrog-cli-v2-jf &&
# Display an introductory message for JFrog CLI jf intro
Artifactory JFrog Client Commands
Ping server
jf rt ping ok
Show config
jf c s # jf config show
Add artifactory
jf c add # jf config add
server id: simple name
url: http://artifactory.example.com/
save and continue (assuming the urls are correct)
username: your username
pass/api: your password or api key
reverse proxy? likely no
jf c add ... CI=true jf c add sandisk --url [url] --artifactory-url [url]/artifactory CI=true jf c add sandisk --url https://artifactory.example.com/ --artifactory-url https://artifactory.example.com/artifactory
Search file
jf rt s [repo/pattern] # pattern can use wild cards
Example:
# jf rt s myrepo/test/BUILD_NUMBER
13:42:58 [🔵Info] Searching artifacts...
13:42:58 [🔵Info] Found 1 artifact.
[
{
"path": "myrepo/test/BUILD_NUMBER",
"type": "file",
"size": 38,
"created": "2023-07-26T18:25:55.912Z",
"modified": "2023-07-28T00:32:13.868Z",
"sha1": "b43cda47086846025ca5aaa6256372bc2550xxxx",
"sha256": "62cce4682d3700b62d5dba0a098b65af928149576f614c51f5c7a03b99xxxxx",
"md5": "bd11639e2c9022ce8ab12d1eda61xxx"
}
]
Access Token Creation
jf access-token-create jf atc
Refresh tokens are commonly UUID-like strings
eg. f1782ce5-5683-444d-8c17-1f62bdace278
Access tokens typically start with:
eyJ...
Reference tokens often start with something resembling:
cmVm...
Create a token that expires in 90 days:
jf atc --expiry=7776000 --description="CLI token"
90 days * 24 hours per day * 60 minutes per hour * 60 seconds per minute = 7776000 seconds
Create a token that expires in 180 days:
jf atc --expiry=15552000 --description="CLI token"
180 days * 24 hours per day * 60 minutes per hour * 60 seconds per minute = 15552000 seconds
Create a refreshable token:
jf atc --refreshable=true jf atc --refreshable
Return a reference token as well:
jf atc --reference=true jf atc --reference
Create a 90 day refreshable token with short reference token:
jf atc --expiry=7776000 --description="CLI token" --refreshable --reference
Example:
{
"scope": "applied-permissions/user",
"access_token": "eyJ....xxx_REALLY_REALLY_LONG_TOKEN_xxx",
"expires_in": 7776000,
"token_type": "Bearer",
"refresh_token": "59372fb0-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"reference_token": "cmVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"token_id": "f28a7682-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Refresh refreshable access token:
ACCESS_TOKEN="access_token content"
REFRESH_TOKEN="refresh_token content"
curl -v \
-X POST \
"https://artifactory.example.com/access/api/v1/tokens" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "refresh_token=${REFRESH_TOKEN}"
If you want to include a reference token:
-d "include_reference_token=true" \
curl -v \
-X POST \
"https://artifactory.example.com/access/api/v1/tokens" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "include_reference_token=true" \
-d "refresh_token=${REFRESH_TOKEN}"
Decode the expiration date: (expiration = creation_time + expires_in)
TOKEN="eyJhbGciOi..."
python3 -c '
import base64,json,time
t="'$TOKEN'"
payload=t.split(".")[1]
payload += "=" * (-len(payload) % 4)
d=json.loads(base64.urlsafe_b64decode(payload))
print(json.dumps(d, indent=2))
print("Expires:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(d["exp"])))
'
# or
echo $TOKEN | cut -d. -f2 | base64 -d | jq .
# "exp": 1787423456
Get tokens:
curl \
-H "Authorization: Bearer $ACCESS_TOKEN" \
https://artifactory.example.com/access/api/v1/tokens
{
"tokens" : [ {
"token_id" : "961cad32-...",
"subject" : "jf-access@a0a259fa-.../users/some.user@example.com",
"expiry" : 1800379731,
"issued_at" : 1784827731,
"issuer" : "jf-access@a0a259fa-...",
"description" : "CLI token",
"refreshable" : true,
"scope": "applied-permissions/user"
}, {
...
} ]
}
NOTE: this also worked:
curl -H "Authorization: Bearer $REFERENCE_TOKEN" \
https://artifactory.sandisk.com/access/api/v1/tokens
API
Test Connection
GET /api/v1/system/ping
curl -X GET "http://ARTIFACTORY_SERVER_HOSTNAME:8082/distribution/api/v1/system/ping"
Ref: https://jfrog.com/help/r/jfrog-rest-apis/test-connection
Get System Info
GET /api/v1/system/info
curl -u myUser:myP455w0rd! -X GET "http://ARTIFACTORY_SERVER_HOSTNAME:8082/distribution/api/v1/system/info"
ref: https://jfrog.com/help/r/jfrog-rest-apis/get-system-info