Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kubo 0.33 with AutoTLS enabled #2917

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"ipfs-utils": "^9.0.10",
"ipfsd-ctl": "10.0.6",
"it-last": "^1.0.6",
"kubo": "0.32.1",
"kubo": "0.33.0",
"multiaddr": "10.0.1",
"multiaddr-to-uri": "8.0.0",
"portfinder": "^1.0.32",
Expand Down
19 changes: 17 additions & 2 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ function applyDefaults (ipfsd) {
config.API = { HTTPHeaders: {} }

config.Swarm = config.Swarm ?? {}
config.Swarm.DisableNatPortMap = false
config.Swarm.DisableNatPortMap = false // uPnP
config.Swarm.ConnMgr = config.Swarm.ConnMgr ?? {}

config.Discovery = config.Discovery ?? {}
config.Discovery.MDNS = config.Discovery.MDNS ?? {}
config.Discovery.MDNS.Enabled = true

config.AutoTLS = config.AutoTLS ?? {}
config.AutoTLS.Enabled = true

writeConfigFile(ipfsd, config)
}

Expand Down Expand Up @@ -150,7 +153,7 @@ const getGatewayPort = (config) => getHttpPort(config.Addresses.Gateway)
*/
function migrateConfig (ipfsd) {
// Bump revision number when new migration rule is added
const REVISION = 5
const REVISION = 6
const REVISION_KEY = 'daemonConfigRevision'
const CURRENT_REVISION = store.get(REVISION_KEY, 0)

Expand Down Expand Up @@ -231,6 +234,18 @@ function migrateConfig (ipfsd) {
}
}

if (CURRENT_REVISION < 6) {
// Enable AutoTLS if there is no explicit user preference
if (config.AutoTLS === undefined) {
config.AutoTLS = {}
changed = true
}
if (config.AutoTLS.Enabled === undefined) {
config.AutoTLS.Enabled = true
changed = true
}
}

if (changed) {
try {
writeConfigFile(ipfsd, config)
Expand Down
51 changes: 51 additions & 0 deletions test/e2e/launch.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,57 @@ test.describe.serial('Application launch', async () => {
expect(config.Swarm.ConnMgr.HighWater).toEqual(undefined)
})

test('applies config migration v6 (explicitly enable AutoTLS if upgrading from Kubo <0.33)', async () => {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

const initConfig = fs.readJsonSync(configPath)
initConfig.AutoTLS = undefined // simulate kubo <0.33, where there was no AutoTLS section
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
const { peerId } = await daemonReady(app)
expect(peerId).toBe(expectedId)

const config = fs.readJsonSync(configPath)
// ensure app has migrated config and AutoTLS is explicitly enabled now
expect(config.AutoTLS.Enabled).toEqual(true)
})

test('applies config migration v6 (explicitly enable AutoTLS if Kubo >=0.33)', async () => {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

// just read config (it should have empty AutoTLS config)
const initConfig = fs.readJsonSync(configPath)
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
const { peerId } = await daemonReady(app)
expect(peerId).toBe(expectedId)

const config = fs.readJsonSync(configPath)
// ensure ipfs-desktop migrated default Kubo config to explicitly enable AutoTLS
expect(config.AutoTLS.Enabled).toEqual(true)
})

test('applies config migration v6 (respect pre-existing AutoTLS user config)', async () => {
// create preexisting, initialized repo and config
const { repoPath, configPath, peerId: expectedId } = await makeRepository({ start: false })

const initConfig = fs.readJsonSync(configPath)
initConfig.AutoTLS = { Enabled: false } // user explicitly disabled it
fs.writeJsonSync(configPath, initConfig, { spaces: 2 })

const { app } = await startApp({ repoPath })
const { peerId } = await daemonReady(app)
expect(peerId).toBe(expectedId)

const config = fs.readJsonSync(configPath)
// ensure app respected and kept user choice
expect(config.AutoTLS.Enabled).toEqual(false)
})

test('starts with repository with "IPFS_PATH/api" file and no daemon running', async () => {
// create "remote" repo
const { ipfsd } = await makeRepository({ start: true })
Expand Down