Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
492609c3
Commit
492609c3
authored
5 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add exp to embed snippets, switch backend unsigning to use :leeway
parent
197aafc6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/public/lib/code.js
+9
-4
9 additions, 4 deletions
frontend/src/metabase/public/lib/code.js
src/metabase/util/embed.clj
+3
-6
3 additions, 6 deletions
src/metabase/util/embed.clj
with
12 additions
and
10 deletions
frontend/src/metabase/public/lib/code.js
+
9
−
4
View file @
492609c3
...
...
@@ -100,7 +100,8 @@ var payload = {
resource: {
${
resourceType
}
:
${
resourceId
}
},
params:
${
JSON
.
stringify
(
params
,
null
,
2
)
.
split
(
"
\n
"
)
.
join
(
"
\n
"
)}
.
join
(
"
\n
"
)}
,
exp: Math.round(Date.now() / 1000) + (10 * 60) // 10 minute expiration
};
var token = jwt.sign(payload, METABASE_SECRET_KEY);
...
...
@@ -132,7 +133,8 @@ payload = {
.
map
(
([
key
,
value
])
=>
JSON
.
stringify
(
key
)
+
"
=>
"
+
JSON
.
stringify
(
value
),
)
.
join
(
"
,
\n
"
)}
.
join
(
"
,
\n
"
)}
,
:exp => Time.now.to_i + (60 * 10) # 10 minute expiration
}
}
token = JWT.encode payload, METABASE_SECRET_KEY
...
...
@@ -154,6 +156,7 @@ const python = ({
`# You'll need to install PyJWT via pip 'pip install PyJWT' or your project packages file
import jwt
import time
METABASE_SITE_URL =
${
JSON
.
stringify
(
siteUrl
)}
METABASE_SECRET_KEY =
${
JSON
.
stringify
(
secretKey
)}
...
...
@@ -164,7 +167,8 @@ payload = {
${
Object
.
entries
(
params
)
.
map
(([
key
,
value
])
=>
JSON
.
stringify
(
key
)
+
"
:
"
+
JSON
.
stringify
(
value
))
.
join
(
"
,
\n
"
)}
}
},
"exp": round(time.time()) + (60 * 10) # 10 minute expiration
}
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
...
...
@@ -191,7 +195,8 @@ const clojure = ({
{:resource {:
${
resourceType
}
${
resourceId
}
}
:params {
${
Object
.
entries
(
params
)
.
map
(([
key
,
value
])
=>
JSON
.
stringify
(
key
)
+
"
"
+
JSON
.
stringify
(
value
))
.
join
(
"
,
\n
"
)}
}})
.
join
(
"
,
\n
"
)}
}
:exp (+ (int (/ (System/currentTimeMillis) 1000)) (* 60 10))}) ; 10 minute expiration
(def token (jwt/sign payload metabase-secret-key))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util/embed.clj
+
3
−
6
View file @
492609c3
(
ns
metabase.util.embed
"Utility functions for public links and embedding."
(
:require
[
buddy.core.codecs
:as
codecs
]
[
buddy.sign
[
jwt
:as
jwt
]
[
util
:as
buddy-util
]]
[
buddy.sign.jwt
:as
jwt
]
[
cheshire.core
:as
json
]
[
clojure.string
:as
str
]
[
hiccup.core
:refer
[
html
]]
...
...
@@ -92,9 +90,8 @@
(
or
(
embedding-secret-key
)
(
throw
(
ex-info
(
str
(
tru
"The embedding secret key has not been set."
))
{
:status-code
400
})))
;; The library will reject tokens with a created at timestamp in the future, so to account for clock
;; skew tell the library that "now" is actually two minutes ahead of whatever the system time is so
;; tokens don't get inappropriately rejected
{
:now
(
+
(
buddy-util/now
)
120
)})
;; skew tell the library to allow for 60 seconds of leeway
{
:leeway
60
})
;; if `jwt/unsign` throws an Exception rethrow it in a format that's friendlier to our API
(
catch
Throwable
e
(
throw
(
ex-info
(
.getMessage
e
)
{
:status-code
400
}))))))
...
...
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